LINQ To Entities - Inheritance with N level Hierarchy
Posted: 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!!!!
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!!!!