Insert Parent and Children

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
dnchris
Posts: 10
Joined: Wed 05 Dec 2012 17:31

Insert Parent and Children

Post by dnchris » Tue 13 May 2014 13:58

We're having an issue with LinqConnect after upgrading from 3.2.x to 4.4.484.

When trying to insert a parent and child records on a single SubmitChanges(), we receive FK constraint violations for the child record.

The new children entities are added to the parent's collections. Our team uses a custom entity template to generate code. The LQML has AutoSync="Insert" for any property that IsPrimaryKey and IsDbGenerated.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Insert Parent and Children

Post by MariiaI » Wed 14 May 2014 12:31

Please specify the following information:
- the DBMS you are working with;
- the DDL scripts of the necessary database tables;
- the definitions of the DataContext class and entity classes;

If possible, please send us a test project, so that we could investigate the issue in more details and find the solution for you.

JIC: we have made a major refactoring of the LinqConnect engine since version 4.0. Since this version the references to System.Data.Linq are removed, LinqConnect uses only its own classes. So, it is necessary to replace all occurrences of "System.Data.Linq." with "Devart.Data.Linq.". Please check that your code (*.Designer.cs file) doesn't contain "System.Data.Linq." and there is no reference to the System.Data.Linq assembly.

Looking forward to your reply.

dnchris
Posts: 10
Joined: Wed 05 Dec 2012 17:31

Re: Insert Parent and Children

Post by dnchris » Tue 01 Jul 2014 22:19

I can't change to the latest version because I'm actively developing in dotConnect for Oracle 6.80.x.

We are using Oracle, but the problem happens at runtime prior to any database connection being established. The best I can do, for now, is provide this pseudo-code:

Where Parent is a POCO with public collection of Child (Children,) and Context is the LinqConnect data context.

Code: Select all

var parent = new Parent();
var child = new Child();

parent.Children.Add(child);

Context.Parents.InsertOnSubmit(parent);

var changeSet = Context.GetChangeSet();
Assert.IsTrue(changeSet.Inserts.Count == 2);
The assertion fails when I attempted to use LinqConnect 4.4.484 with no references to System.Data.Linq.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Insert Parent and Children

Post by MariiaI » Wed 02 Jul 2014 12:50

Thank you for the additional information. We have reproduced this issue. We will investigate it and inform you about the results as soon as any are available.
To resolve the issue, please rewrite your code in the following way:

Code: Select all

Parent parent = new Parent();
 Child child = new Child() { Parent = parent };
 Context.Parents.InsertOnSubmit(parent); 
 var changeSet = Context.GetChangeSet();       
 Context.SubmitChanges();
Please also refer to http://www.devart.com/linqconnect/docs/ ... lated.html.

dnchris
Posts: 10
Joined: Wed 05 Dec 2012 17:31

Re: Insert Parent and Children

Post by dnchris » Tue 05 Aug 2014 20:21

We can re-write some of our code, but if there has been any movement on this we'd rather download the updated version. Thanks.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Insert Parent and Children

Post by MariiaI » Wed 06 Aug 2014 05:26

We are working on this issue. We will definitely inform you about the results as soon as possible.

dnchris
Posts: 10
Joined: Wed 05 Dec 2012 17:31

Re: Insert Parent and Children

Post by dnchris » Mon 08 Sep 2014 13:43

Did 4.4.577 address this issue?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Insert Parent and Children

Post by MariiaI » Mon 08 Sep 2014 14:32

dnchris wrote:Did 4.4.577 address this issue?
No, this build doesn't include the fix for this issue. We are working on it, but we can't tell any timeframe at the moment. We will definitely inform you about the results as soon as any are available.

anamta
Posts: 1
Joined: Fri 03 Oct 2014 20:23

Re: Insert Parent and Children

Post by anamta » Fri 03 Oct 2014 20:28

We are looking forward to your reply with the additional information.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Insert Parent and Children

Post by MariiaI » Fri 07 Nov 2014 11:56

We have investigated this behaviour and it is related to the POCO limitations.
Currently, there are no plans to make any changes for such scenarios.
Please use the workaround, which is described above.

Post Reply