DataAnnotations IsValid not working

DataAnnotations IsValid not working

Old forum URL:

AaronH posted on Friday, July 02, 2010

I'm using CSLA SL 4.0 beta 3.  Today I tried applying data annotation attributes to a few properties of a class.  I am not overriding AddBusinessRules().  When I create a new instance of the object on the SL side, the object.IsValid property is still true, when it should be false. 

I see that AddBusinessRules() in the base is calling BusinessRules.AddDataAnnotations(), but for some reason, it's not finding the attributes on my properties.

Here is one of my properties:

        private static readonly PropertyInfo<string> _notesProperty = RegisterProperty<string>(p => p.Notes);
        public string Notes
            get { return GetProperty(_notesProperty); }
            set { SetProperty(_notesProperty, value); }

Any thoughts?

AaronH replied on Friday, July 02, 2010

Nevermind, for some reason it is now working.  Not sure why, the code hasn't changed.  I'll report back if I see this behavior again.

marthac replied on Wednesday, January 26, 2011

Try making the PropertyInfo public. There are problems with SL when this is private.

Copyright (c) Marimer LLC