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
|
Is there a way to ValidatePresence on Nullable Foreign Key Field? |
|
|
No - the ValidatePresence rule is used to indicate it has to be present (e.g. not nullable). Can you elaborate on the situation you are thinking you would apply this to?
|
|
|
This was part of a possible solution to the other issue posted; we were going to mark all fields as Nullable then set ValidatePresence when needed. In the example below UserAccountId is a Non Nullable FK Field. Id Name UserAccountId 1 Jon 45 If we edit the record for Jon, and Post a null value from the form for UserAccountId, the value 45 will remain and ModelState will be reported as IsValied==true. Since no value was posted, we would expect IsValied==False with a Required Field error message that we could display on screen. Also, is there a way to tell if a property of an Entity has been set? I cannot find a way to tell if a value was set by the user or is the default for a non nullable field. Thanks, |
|
|
You can use the change tracker to determine what properties have been modified (or you could hook the OnPropertyChanged and track it yourself). You can use the ValidatePresence if you want to validate that a non default value has been set for a non nullable field, otherwise you could just compare it to the default value for the given value type being operated on if you wanted to do something more manual - e.g. http://stackoverflow.com/questions/7068043/how-to-get-the-default-value-for-a-valuetype-type-with-reflection
|
|