LinqConnect Professional Version 4.1.184 (07-Feb-2013) - problem when delete.

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
AKRRKA
Posts: 198
Joined: Thu 26 Jan 2012 15:07
Location: Russia
Contact:

LinqConnect Professional Version 4.1.184 (07-Feb-2013) - problem when delete.

Post by AKRRKA » Wed 27 Feb 2013 14:32

I created date context and added new rows to a table using InsertOnSubmit() method and submit changes using SubmitChanges() method.

Then I deleted some row using DELETE console command.
By sample:

Code: Select all

DELETE FROM `Values` WHERE (`Values`.`PropertyId` >= 1 AND `Values`.`PropertyId` <= 4)
Then I added same rows like deleted and tryed to submit changes.

An expeption raised:

Code: Select all

Unexpected state of the updated entity 'ceContext.Value': e.
Devart.Data.Linq.Engine.SubmitCommandBuilder.b(IObjectEntry A_0, MetaType A_1, IEnumerable`1 A_2, Int32& A_3, Int32& A_4, StringBuilder A_5, List`1 A_6, List`1 A_7, AutoSyncMode& A_8)\r\n 
Devart.Data.Linq.Engine.SubmitCommandBuilder.a(IObjectEntry A_0, MetaType A_1, IEnumerable`1 A_2, StringBuilder A_3, List`1 A_4, List`1 A_5, AutoSyncMode& A_6)\r\n 
Devart.Data.Linq.Engine.SubmitCommandBuilder.a(IObjectEntry A_0)\r\n 
Devart.Data.Linq.Engine.b4.c(IObjectEntry A_0)\r\n 
Devart.Data.Linq.Engine.b4.a(IObjectEntry[] A_0, ConflictMode A_1, a A_2)\r\n 
Devart.Data.Linq.Engine.b4.a(ConflictMode A_0)\r\n 
Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)\r\n в 
What do I wrong?
Thanks.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Re: LinqConnect Professional Version 4.1.184 (07-Feb-2013) - problem when delete.

Post by StanislavK » Wed 27 Feb 2013 17:39

As far as I understand, you performed these actions on the same DataContext instance. Am I correct? If yes, this is an expected behaviour: DataContext caches the inserted entities and is unaware that they were in fact deleted. So, when you insert the same object again, DataContext raises an exception, as this entity is already available in context's cache.

A general recommendation is to create one DataContext per unit of work, and dispose it as soon as this unit of work is finished:

Code: Select all

// Insert an entity for the first time:
MyDataContext context = new MyDataContext();
context.MyTable.InsertOnSubmit(
  new MyEntity () { ... }
);
context.SubmitChanges();

// Delete the corresponding row.

// Insert an entity with the same key again:
context = new MyDataContext();
context.MyTable.InsertOnSubmit(
  new MyEntity () { ... }
);
context.SubmitChanges();

AKRRKA
Posts: 198
Joined: Thu 26 Jan 2012 15:07
Location: Russia
Contact:

Re: LinqConnect Professional Version 4.1.184 (07-Feb-2013) - problem when delete.

Post by AKRRKA » Thu 28 Feb 2013 12:44

Thanks!

Post Reply