Search code examples
data-annotationswcf-ria-servicessilverlight-5.0

Writing DataAnnotations best approach


What could be the best approach to write DataAnnotations and not losing them when the Domain Service has to be regenerated?

What I do is to have a copy of the DomainServise.matadata.cs file, then if I regenerate the Domain Service, I take those annotations back from the copy. Is there a better way?


Solution

  • DataAnnotations attributes are usually copied from your entity defined server side to the entity generated client side. (it's also possible to inject those attribute through a custom metadata provider, so that you don't add dependencies to your model, in my blog I've done it with nhibernate)

    Take a look at this tutorial, and see if it fit your needs.
    There was also sample from Microsoft on how to create a custom WCF Metadataprovider based on xml file, and I have bookmarked it at his address : http://code.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=2659 but the link seems no longer active, if this is rather what you needs I can try to find it on my backup hard disk ;)

    Finally, take also a look at WCF RIA services domain service metadata, ther's a sample that use partial class, the wcf ria services default way (though you have to add dependency to system.servicemodel assembly for some attributes)