locked
Can we create a partial class of metadata for adding validations? RRS feed

  • Question

  • Hi,

      I am using RIA Service and Entity Framework

      I have a Domain service class added for which metada.cs is autogenerated.

      I have decorated some properties with Regular Expressions and Custom Validations in the metadata.

      Whenever I regenerate Domain Service class, the metadata is regenerated and I have to go and again decorate the properties in metadata with required validations.

     Is there any way that I can write this validations in some partial class so I need not take care of decorating properties whenever my metadata is regenerated?

     

    Friday, August 27, 2010 7:49 AM

Answers

All replies

  • Hi,

    While it is easy to add methods and new properties to a class via partial classes, you cannot really modify existing properties via a partial class extension. Maybe you can consider not autogenerating metadata file, instead, you can try to write it on your own 

    Monday, August 30, 2010 12:48 AM

  • Yes. Partial classes are great for this. In our project we approach validation at the object level since some fields interrelate with each other. When insert or update is called we call a validation method in the object. if the object is invalid a validation error can be added and the insert or update does not take place.

    This method can also be shared with the client. The client can call it to see if all will be well before calling submit changes.

    Monday, August 30, 2010 12:59 AM
  • Yes, you can use partial classes and there are instructions on the WCF RIA Services wiki on how to do that.

    Monday, August 30, 2010 9:02 AM