Sunday 15 July 2012

c# - Can't add a record twice with Linq to SQL -


In the heritage system, I want to add the same record twice in a table.

There is an identity on the table which increases with each new record.

If I do the following, I get an error: "Can not add an existing entity"

Is there any other pricing snapshot object Is there any way to add a record twice without making it?

  Pricing Snapshot pricing snapshot = new pricing snapshot {invoiceorder leaderid = invoiceorder lines id, grosspayment = gross total, created = "price engine", created date = date time.Now}; DBpostChanges.PricingSnapshots.InsertOnSubmit (pricingSnapshot); DBpostChanges.SubmitChanges (); DBpostChanges.PricingSnapshots.InsertOnSubmit (pricingSnapshot); DBpostChanges.SubmitChanges ();  

For the first time after the change, you will have to create a new pricing snapshot object, your The object pricing snapshot is still present and the ID is now assigned to your table. So if you were trying to reach the ID of the submitted object for the first time, you will get one of it, so adding a duplicate will be added to it again in the table.


No comments:

Post a Comment