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 our project we some times have the need to create lightspeed entities (sampleEntity1) 'offline'. To do so we just create a entity and never execute the unitofwork.add(sampleEntity1). The problem is that our sampleEntity1Type references a sampleEntity2Type (which has a reverse association with sampleEntity1). If we link sampleEntity1 to a sampleEntity2 (already in the DB) and then execute unitofwork.savechanges(), the sampleEntity1 is added to the database even if the unitofwork.add(sampleEntity1) was never explicitly executed. Example: using (unitofwork)
{
sampleEntity1Type seT1 = new sampleEntity1Type(); Is there any way to overcome this problem? Thanks |
|
|
When an entity is associated with an existing entity it is attached to that entities UnitOfWork, because the entity is new it is then persisted when you call SaveChanges(). If the SampleEntity1 instance is transient why do you need to associate it with the Sample2Type?
|
|
|
The entity is created in a generic way, all associations included. After that, if it is new, it is saved, which will lead to no troubles. But if it is not new but an update the required fields are copied across to another entity and the initial entity is not added (but it is due to the ReverseAssociation of some of its associations). |
|
|
You will want to detach the unwanted entity from the UnitOfWork so it isn't considered for persistence. e.g.
Also make sure you are unwiring it from any associations prior to detaching otherwise it may inadvertently get re-attached if the association is ever traversed again.
|
|