This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am using the [ValidatePresence] attribute on a boolean field, and then setting the value of that field in the constructor. When I call the IsValid method on the entity, validation fails, telling me that the moderated field is required. Am I missing something? I use the same approach to set another field without any issues. |
|
|
Hi Mark, When ValidatePresence is applied to a value type, the "empty" value is assumed to be the default value for the type - in the case of bool: false. Are you simply resetting the moderated field to false in the constructor? If so, this is not required as value types are auto-initialized to their default value i.e. are never null. Solution: either make the field a nullable bool or remove the ValidatePresence as the bool field will always have a value (false by default). Cheers, Andrew.
|
|
|
I am still playing at the moment, but is there a way to change the default value for a type? I assume that the default value for a DateTime is 1 Jan 1900, but I don't set my DateTimePickers to that date else it would be a mission to scroll through to the current date - so they all sit at DateTime.Today. In the case of a DOB field, the user has to be of a certain age, so comparing the value to the default (Today) date returns a message to the user - it's not perfect but it means there is just that basic check for the user. I realise that I could make a validator for the entire case (age > 15 for example) but DOB is just an example I got off the top of my head that I wouldnt necessarily like to write a validator for, but it could be anything where the day had to be a day other than today. Of course, this might already be the case, in which case: whoops ;) Cheers :) Jono |
|
|
Ooh, I see the ValidateComparisonAttribute now, which I am sure I could work to do what I wanted :) |
|
|
Glad to be of service :-) |
|