views:

50

answers:

1

It would be great if someone can point me in the right direction on this topic

I have the following admx: http://img339.imageshack.us/img339/7817/entitydesignerdiagram2.png

And I have to add the (AccData, CntactData, PhnNumber, FnclDetail)entities to the database in one shot What’s the best practices to do the add operation for the above entities??

alt text

+1  A: 

If you have Navigation properties created over foreign keys in your database then there should be no problems in assignment. Set the detail entities to the navigation properties of their masters, like this pseudo code:
//Create an accData instance in some way
accData.PhnNumbers.Add(phnNumber);
accData.CntactData.Add(cntData);
//Load the FnclMaster in some way, for example,
FnclMaster master = db.FnclMasters.Where(it=>it.FnclprdIdCode == myCode && it.AccNo == myAccNo);
master.FnclDetails.Add(fnclDetail);
context.AddToAccDatas(accData);
context.SaveChanges();

Devart
Thank you so much Devart ,,,If I need to add the entites(CntactData, PhnNumber)with a new other entity(GnlData) that doesn't have any relation with them ,thant means I don't have foreign keys and the 3 entities are Separated.How can I add these entites on one time?
kathy
In fact, when you call SaveChanges, all inserts, updates, and deletes that were made during the context lifetime since the last SaveChanges call or since the context was instantiated are operated in a single transaction, so usually there is no need to do anything except SaveChanges.
Devart
I thought when I add entities with no relation between them that means I have to use the complex type to do this operation??
kathy
Not quite. This applies in a way to entity properties. Take a look at these articles for more information: http://msdn.microsoft.com/en-us/library/bb336792.aspx (about SaveChanges) http://msdn.microsoft.com/en-us/library/bb738695.aspx (a bit of general information)
Devart
Thank you for your help
kathy