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
|
Hi, I'm aware there is an converstation going on about adding Unique validation on single column automatically. Is the multiple column constraint validation in the picture of future version of LightSpeed? The reason we asked is that we have multi column unique constraint in our database (currently). and the latest nightly build (24th May) only add validation on one column, this break our test cases unexpectedly. Do you have any suggestions for the meanwhile? Many thanks. Nathan |
|
|
We're unlikely to be adding this capability in the near future. You can however perform this validation yourself by overriding Entity.OnValidate: protected override void OnValidate() { (If you're using soft deletion, add IncludeDeleted() to the query.) |
|
|
Hi Ivan, Thanks for the quick reply. And the suggestion. The problem we had wasn't to do with how to perform validation. It's the LightSpeed code generator add "ValidateUnique" to only one column despect the fact there are two column involved in making the unique constraint. Is that possible to perform a little check when adding this attribute? Otherwise, we either need to drop the unique constraint from the database, or we have to ignore the Update Model popup every time we click "Update from Source" on the model designer Cheers, Nathan |
|
|
Oops, sorry for the misunderstanding. No, there's no way to change the designer update behaviour, though of course you can clear just the checkbox for the "apply uniqueness validation." I can probably get this fixed for 3.1, but may not be able to do it for all databases. Which database are you using? SQL Server? |
|
|
Wow, if you can put it in 3.1 it would be fantastic. We are on SQL Server 2008. |
|
|
Okay, this is in. If a column is part of a multi-column unique constraint, the designer will NOT set up a unique validation on the corresponding property, just as if the unique constraint were not present. For availability, watch for the 3.1 release announcement on the blog. For 3.1, this will only apply to SQL Server; we'll roll out the fix to other databases in the post-3.1 nightly builds. |
|
|
Legend, Ivan |
|
|
[quote user="ivan"]We're unlikely to be adding this capability in the near future.[/quote] Any changes for that up for now? I mean automatic validation for multi column Unique Index. |
|
|
Maybe I haven't clearly understand you, but should it work in LightSpeed 4 and Oracle. Because we have such problem - Model generated from Oracle database (having table with Unique Index made up of several column) has two properties with ValidateUniqueAttribute on both... |
|
|
You have understood correctly. LightSpeed doesn't currently support validating uniqueness on a multi-field set. The built-in uniqueness validation checks only that the field it is applied to is unique. You might be able to kludge a two-field validation by setting the scope of each uniqueness validation to the other field, but there would be performance implications (two checks rather than one). |
|
|
Thinking about it, a better solution is probably to do the multi-field uniqueness validation in an OnValidate override, and not have uniqueness validations on the fields at all. |
|