LINQ To Entities - Inheritance with N level Hierarchy
LINQ To Entities - Inheritance with N level Hierarchy
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!!!!
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.
I have looked, there is no e-mail address in you forum profile.
http://devart.com/forums/profile.php?mo ... ile&u=8462
http://devart.com/forums/profile.php?mo ... ile&u=8462
My problem was solved !!!
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 !!
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 !!