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 have an entity, ProductUser, that is used to track what products a user uses. It has three properties: the product, the user and IsTrained (boolean). This entity has many to one relationships with the Product entity and the User entity. I am getting errors when trying to SaveChanges on the unitofwork. Here's the code I'm using to create the entity.
prodUser = New Objects.ProductUser I am getting errors sayin that IsTrained is invalid, User is invalid and Product is invalid. I know for a fact that user and product are valid entity objects since I validated them earlier in the code. Is this the correct way to create this entity? correctly. Thanks |
|
|
Hi Steve, What validations do you have set on the IsTrained property? One of these will be triggering the validation error. The User and Product are reporting as invalid because the ProductUser object you are dealing with is invalid and so it makes the association User/Product objects invalid by association.
Jeremy |
|
|
It looks correct from the code fragment you've posted. Drilling into the Errors collection it should provide more detail on *why* LightSpeed thinks these things are invalid, which might make it clearer what's going wrong. If that doesn't shed any light, we'd probably need to see a bit more of a repro. Also, I do recall an issue where some kinds of entities could run into problems if you set associations before adding the entity to the UOW. I don't think these manifested as validation errors, and don't have the details to hand, but you could try doing: unitOfWork.Add(prodUser) before setting User and Product, and see if that changes things. It *shouldn't* be necessary but it may be worth a try. |
|
|
I have Validate Presence set to true and Is Nullable set to false for IsTrained. I changed the Validate Presence setting to false and the entity updated just fine. So, for a boolean it appears that Validate Presence really means Validate True. Since Is Nullable is false then it would seem that either a true or false setting would be ok for Validate Presence. What's your thinking on why Validate Presence works this way for a boolean? |
|
|
Validate Presence effectively means "the value must be something other than the default" -- not 0 for numeric types, not null for strings... and, logically, not False for booleans. Consequently, Validate Presence on a non-nullable boolean is pretty much meaningless, because the logical interpretation of "present/not present" is useless (it allows only True, in which case why bother having a property for it at all), and there's no useful concept of "present/not present" that we could use instead. Maybe we should just make Validate Presence a no-op on non-nullable booleans. In addition, it sounds like we're inferring it in the designer when we shouldn't be: I'm assuming you dragged the entity from a database rather than creating it by hand, is that right? If so, I'll take a look at this. |
|
|
Actually, this was an entity I created in the designer and then populated into the database. Not sure what you mean by "no-op". I don't think it would be good to have the samee behaviour regardless of whether the property is set to true or false. I'd rather see you disable the Valid Presense property for non-nullable booleans. |
|
|
Done! It'll be in the 7 July nightly build. |
|