Page 1 of 1

Master-Details problem

Posted: Thu 03 Mar 2011 15:23
by Alladin
Does DevArt EF driver support 0..1 to *..Many relations?

A have two classes IndexDetails and IndexMaster. IndexDetails has a nullable reference to IndexMaster class. IndexMaster class has a collection of IndexDetails instances.

When I add a new IndexMaster, then add a new IndexDetail to the Details collection, all key and reference properties are correctly set.

However, when I do this:
1) Create new IndexMaster A
2) Create new IndexDetails B and add it to the master A
3) Context.SaveChanges <-!!!!!!!!! Oracle exception foreign key not found.

When I do it like this:
1) Create new IndexMaster A
2) Context.SaveChanges (Save master object) - works
3) Create new IndexDetails B and add it to master A
4) Context.SaveChanges (Save child object) - works

Now the question, is EF provider supposed to resolve dependencies and execute inserts in correct order? Or should the developer know in which order he has to save his entities?

Posted: Thu 03 Mar 2011 16:12
by AndreyR
I have sent you a simple sample project illustrating the working scenario with 0..1 - * association.
Could you please make some corrections to reproduce the error?

Posted: Thu 03 Mar 2011 16:35
by Alladin
Thank you.

The problem was that Foreign Key Constraint was missing. Without this information, it's not obvious, that master object must be inserted before the child.

Posted: Thu 03 Mar 2011 16:51
by AndreyR
Glad to hear that the issue is resolved.