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
|
In unit tests, we have this fragment of code:
Store beingValidatedInstance = CreateNewBusinessObject();beingValidatedInstance.StoreCode = "x-x"; // here is the unique validation Store beingValidatedInstance2 = CreateNewBusinessObject();beingValidatedInstance2.StoreCode = "x-x"; // here is the unique validationusing (UnitOfWork uof = dlWorkingContext.CreateUnitOfWork()){
} One would expect, that uof.SaveChanges() should lead to throwing the validity check exception, since uniqueness of the Store.StoreCode property is broken, but no exception is thrown.. Do we do something wrong? |
|
|
You're not doing anything wrong, but uniqueness validation runs against the database. It therefore considers only entities that are currently in the database, not pending inserts or updates. (Consequently, also, an entity with a pending delete can still trigger a uniqueness validation failure.) As a possible workaround, could you perform a SaveChanges after adding *each* entity, and use a transaction to ensure atomic commit behaviour? This is less efficient than batching if you have large numbers of entities, but should be okay if you are saving only relatively small numbers in each go. |
|