none
Async validation data attribute with separated DAL layer?

    Question

  • Hello !

    I have a silverlight RIA project with my DAL based on Entity Framework on a separated dll. The "WebProject" has a reference to the DAL and contains my "DomainService" exposed to Silverlight app.

    I want to add a custom validator attribute doing something like async "Unique ID checker".

    If I put my custom attribute class on the DAL project, I haven't access to the current "DomainService" to do my business validation logic because my DAL don't have references to the "Web Project". And I can't add an reference to it because it creates a "Circular References problem".

    How can I solve this ?

    Thank you for any response.

    Wednesday, April 11, 2012 12:09 PM

Answers

All replies

  • Add a partial class in your web or client project for your entity and add your validator to that partial class.

    Note: Partial classes should be in the same namespace as the original class, write your partial class in a namespacse decleration with the same name.

    Wednesday, April 11, 2012 7:22 PM
  • Hello thanks for your responses !

    I have already my Metadata classes in my DAL project. Are you sure I can add an another partial class definition on another assembly (in the web project)? It doesn't seems to works...

    Thank you for links it could help.

    Thursday, April 12, 2012 5:34 AM
  • Yes, you can add partial classes in silverlight client, as far as your wcf ria services link web assmbly has a reference to that assembly.

    I thought you could add in web project too, i tried but it seems doesnt work. But generaly i add partial classes in silverlight client

    Or if i will use same domain service in more than one silverlight client, i add a Domain service class library and add validators or calculated fields in partial classes in silverlight library then i add a reference to the silverlight library to my sliverlight client projects.

    Thursday, April 12, 2012 6:50 AM
  • I can't get it works !... Frown

    I can't add custom validation attribute on my entity property on client-side library on the partial class definition... And I'am a little bit confused of how it works now...

    Do you have any sample solution with good configuration ? Thanks for your help.

    Thursday, April 12, 2012 12:04 PM
  • I have added a simple demo here (AsyncValidationDemo)

    https://skydrive.live.com/redir.aspx?cid=a0d9cae187592026&resid=A0D9CAE187592026!139&parid=root

    Validation is in client project AsyncValidation, see Model Folder.

    Thursday, April 12, 2012 1:20 PM
  • Thank you very much for your sample !

    The difference with what I was doing is that I was trying to but my custom validator attribute on a property of my entity and not on the entity partial class... That was what I was missing !

    Thanks again for time you spend for me. This was very helpfull.

    Thursday, April 12, 2012 5:27 PM
  • You are welcome.

    I commented out some parts in PropertyChanged event,  if you validate your property that way you won't need a custom validator.

    You shouldnt use custom validator on entity class for async validation, it was only for demonstration purpose, becuase class validators doesnt check validity when a property changed but only when you validate whole class , for example when you commit in a dataform, and dataform will see entity as valid even if it is not, because it wont wait server response.

    For async validation, if you dont have acces to property definition as is the case for you because you dont have acces to domain service in your model class and need to validate client side, you must use the way i commented out.

    For sync validation you can use a validor if you need to validate whole class.

     

    Thursday, April 12, 2012 6:04 PM
  • hello e066377.

    can you send "async validation example" file for me. i can't download it.

    my email:(iliaakbarifard110@gmail.com).

    thanks.

    Wednesday, May 16, 2012 1:02 PM