I am working on one project where I have to persist data with multi level table relations. Let me simply explain the scenario with table design.
Customer table [ columns: customer_id (PK) int <Identity>, customer_name varchar(50)]
Orders table [ columns: order_id (PK) int <Identity>, order_desc varchar(100),
OrderItems table [columns: item_id (PK) int <Identity>, item_desc varchar(100), item_price decimal(18,6),
See above mentioned 3 tables Customer, Orders and OrderItems along with PK->FK relation. Let me give a simple example. I create Customer then Create an Order (one to many) and for each Order I create Order Items (again one to many)
So here is how I would like to persist my Customer -> Order -> Items info
Customer1 = C1, Order = O1, Item = I1, I2, I3
My code goes like this
string cnstr = "server=SQL01; database=MyDB; Integrated Security=SSPI;";
MyComp.CUSTDAL.Business.ConfigurationValues.GetInstance().ConnectionString = cnstr;
CustomerCollection cc = new CustomerCollection();
Customer c = cc.NewItem();
c.customer_name = "C1";
OrderCollection oc = new OrderCollection();
Order o = oc.NewItem();
o.order_desc = "O1";
ItemCollection ic = new ItemCollection();
Item itm = ic.NewItem();
itm.item_name = "I1";
itm.item_price = 400.00M;
//-- Add OrderItems to the Order
//-- Add Orders to the Customer
//System.Data.DataRelationCollection dr = cc.SubDomain.Relations;
In the above code I am persisting data at Customer leve (The root or first level) but it is persisting only Customer and Item.
If I do perist at Order level (i.e. oo.Persist() or oo.SubDomain.Perisist()) then it persit only Order and its Item.
With this, it looks like nHydrate is not doing data persisting with multi level table relation. Or Am I missing something?
If you have any clue or resolution please help.