views:

406

answers:

2

I am uisng Silverlight 3 and ADO.NET Data Services with a cusotm-built Model (separate project) and DAL (separate project)) in place. Within my Silverlight project, I create a [Service Reference] that references my .svc file that in turn points to my Model.

Here's my question: I would like to use the rich features of DataAnnotations (System.ComponentModel.DataAnnotations) but where exactly do I put these attributes? If I decorate by Model with these annotations, I don't see them rendered in my [Service Reference]-generated proxy code. I just see my classes with its members, but no DataAnnotations (Reference.cs).

I know if I manually change the (Reference.cs) file and add some DataAnnotations, these changes to trickle throught to my Silverlight Client. I don't believe I should be updating generated code, i.e. proxy code w/in (Reference.cs). So, my question is, where in my Visual Studio structure of separated projects (Web, SL, Model, DAL), do I throw/extend this custom datasource (Model) to utilize DataAnnotations?

I would like something like this:

[Required]
public string FirstName
{
    get
    {
     return this._FirstName;
    }
    set
    {
     this.OnFirstNameChanging(value);
     this._FirstName = value;
     this.OnFirstNameChanged();
    }
}
A: 

I have a replacement code gen for producing ADO.NET Data Service proxy classes and adding in the validation automatically in my Niagara Project:

http://niagara.codeplex.com

Shawn Wildermuth
Thanks Shawn for your reply. Aside from using your project (needed password once I downloaded the code and trying to build), can you please assist me with my question? How can I extend my partial classes that are generated by the proxy service to decorate my members?
A: 

I think checking this article out might give you some insight as to why Shawn posted his comment. The short answer to your question is. Follow the ModelView-View-Model (MVVM), style of silverlight development, then place DataAnnotations on the properties in your Model, its a huge topic and you need to read and understand it first. I suggest you check out RIA services,(i think its know as WCF services now), that will help you out alot if you want to propagate Validation logic from the WCF service, back to the client.

Neil