c# - Linq to sql object is marking it to insert automatically -
I am creating a clone of some organizations so that they can be bound to some grid and some changes to avoid objects Can be done such as:
var clonients = data contacts. Some tableau FirstOver Default (). Some ChildTable.Select (x = & gt; New SomeChildTable {SomeProperty = x.SomeProperty});
Some properties are not primitive types but rather data contact items (other entities). After doing so that the objects on clonitives
are marked as I did SomeChildTable.InsertAllOnSubmit (cloneEntities)
, which I did not do.
If I don
not to mark the properties of any entity, not to be included in the objects.
How do I get child institution cloned without having to be cloned without putting it?
Thanks
UPATE: It seems that I am not expressing enough, therefore, give examples.
We have an employee and store table, some employees can work on many shops, so you have an employee store table to keep track of employees working:
Employee ======= Code Insul Faucet Identification (1,1) Name varchar (20) Code Primary at the code store ===== Code int null identification (1,1) Name varchar (20) code Primary employee employee ============ CodeEmployee int codeStore CodeEmployee and primary primary on CodeStore
If I I am editing the charity so I want to present the store on the grid and they should be able to add new stores
Firstly it works, but if I try to update some line on the grid (Instead of removing the store A, the user and store B in the grid line with Store A, and selects store B) I got an exception because I am trying to modify the employee store I am trying. StoreCode is a part of the primary key.
So instead I want to do something like this:
var employee = data content Empire first (); Var Clonauts = New Binding List & amp; Employee Employee & gt; (Employee Select wires (x = & new employee store {store = x.store})); // go to the grid from the store and later datetext. Store Empireist. Deloelombeit (Staff Stars); Employee.Stores.AddRange (clonedStores); DataContext.SubmitChanges ();
But that does not work, because the moment I make clonedStores
is marked as I have InsertAllOnSubmit ()
, then this accident occurs if I try to remove the employee's object.
It seems that I am doing some wrong wrongdoing, but I do not know, because this is such a common scenario.
Thank you for your help and ideas.
Your problem is that you are adding child organizations back to the statement for the same unit in :
var clonients = data constants Some tableau FirstOver Default (). SomeChildTable.Select (x = & new; New {SomeProperty = x.SomeProperty});
Update:
Depending on the new information, you have prioritization preferences, I will suggest some suggestions like this:
var institutions TOOMove = DataContext.SomeTable.FirstOrDefault (). SomeChildTable; Forefront (some child-item item integrativ) data contents. Some tables Where (A = & gt; AK some. Eligible == new ID). Some childtable.add (item); DataContext.SubmitChanges ();
In this way, you are not worried about removing anything ... You are only updating foreign key references to child records.
Update # 2:
What you should do is change the employee structure of the employee employee in this way:
Employee Store_IndIntault Identity (1, 1) codeEmployee int (FK for Employee) CodeStore Int (FK to Store)
When you correct your foreign key relationships By the way, LINQ-to-SQL works best, this composite does not really like the primary keys; Are that when you were an exception in an attempt to change the value CodeStore
.
Once this happens, you should have an existing store in the Employee Store. The codestore is capable of reassigning an employee to a different store by changing the existing
Store.Code
and calling DataContext.SubmitChanges (). >.
Comments
Post a Comment