LINQ To Entities - Inheritance with N level Hierarchy

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
mirra
Posts: 12
Joined: Fri 09 Jan 2009 13:29
Location: Ukraine

LINQ To Entities - Inheritance with N level Hierarchy

Post by mirra » Wed 21 Jan 2009 09:28

Hello!!
I have EDM:
Object
/ \
Document File
/ \
Contract Account

Here I use TPT and TPH.
Entities Object, Document, File stored in table Object. (Entities Object, Document of abstract types) - Table Per Hierarchy(TPH).
Entities Contract, Account stored in tables Contract, Account accordingly. - Table Per Type(TPT).
Physically tables are connected one-to-one: Object [1] -[1] Account, Object [1] - [1]Contract.
I can send file EDM.edmx. if it will help.

MY QUESTION:
How to create object Contract and to add it to objects of entities Contract-Document-Object?
Physically in database should be 2 records are added:
In table Object and Contract.

I DID SO:
using (Entities entities = new Entities(connectionString)) {
EDMClassLibrary.Contract newContract = Contract.CreateContract(4, DateTime.Now, DateTime.Now, DateTime.Now, "Popov", 777, "Content", "Andropov");
entities.AddToObject(newContract);
entities.SaveChanges();
}
Error: System.Data.UpdateException -
{"An error occurred while updating the entries. See the InnerException for details."}


P.S.
I have studied articles:
http://msdn.microsoft.com/en-us/library/bb738529.aspx
http://msdn.microsoft.com/en-us/library/bb738570.aspx
But for my model I can not make.
Thanks!!!!







Last edited by mirra on Thu 22 Jan 2009 06:08, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 21 Jan 2009 11:41

Please provide more detailed description of the problem.
What is the InnerException message?
If possible, send me (andreyr * devart * com) a small test project illustrating the issue.

mirra
Posts: 12
Joined: Fri 09 Jan 2009 13:29
Location: Ukraine

Post by mirra » Wed 21 Jan 2009 12:07

I have not understood on what address I can send the test project :roll:

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 21 Jan 2009 12:35

Send the project to email available in my forum profile.

mirra
Posts: 12
Joined: Fri 09 Jan 2009 13:29
Location: Ukraine

Post by mirra » Wed 21 Jan 2009 13:04

I have looked, there is no e-mail address in you forum profile.
http://devart.com/forums/profile.php?mo ... ile&u=8462

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 21 Jan 2009 13:17

Sorry, it was hidden. Try again now.

mirra
Posts: 12
Joined: Fri 09 Jan 2009 13:29
Location: Ukraine

Post by mirra » Wed 21 Jan 2009 13:25

All, I have already sent!
There is a mistake In WindowsFormApplication1 in file Form1.cs

mirra
Posts: 12
Joined: Fri 09 Jan 2009 13:29
Location: Ukraine

Post by mirra » Thu 22 Jan 2009 07:32

My problem was solved :D !!!
All is very simple:

Contract newContract = new Contract();
newContract.IdObject = 4;
newContract.Name = "Contract 4";
newContract.NumberDoc = 1122;
newContract.DataRegDoc = DateTime.Now;
newContract.RegistratorDoc = "RegistratorContract4";
newContract.DatePodpisi = DateTime.Now;
newContract.DateStart = DateTime.Now;
newContract.DateFinish = DateTime.Now;
newContract.Summa = 888;
newContract.Podryadchik = "Mishenko";
newContract.Zakazchik = "Kalinina";
newContract.Text = "Content of Contract4";
entities.AddToObject(newContract);
entities.SaveChanges();

To create the bottom object of hierarchy, it is necessary to set all attributes of a branch of a tree consistently.

At me was: Contract---Document---Object.
Object:
newContract.IdObject = 4;
newContract.Name = "Contract 4";
Document:
newContract.NumberDoc = 1122;
newContract.DataRegDoc = DateTime.Now;
newContract.RegistratorDoc = "RegistratorContract4";
Contract:
newContract.DatePodpisi = DateTime.Now;
newContract.DateStart = DateTime.Now;
newContract.DateFinish = DateTime.Now;
newContract.Summa = 888;
newContract.Podryadchik = "Mishenko";
newContract.Zakazchik = "Kalinina";
newContract.Text = "Content of Contract4";


Thanks big, AndreyR !!


Post Reply