How to update Foreign key

Sep 13, 2010 at 12:44 PM

 

I have following database structure,

* TblMastCustomer ( ID (indent,int), Name varchar(50))  << BusinessListBase>>

* TblMastAddress (ID (indent,int),CustomerID (int), Add1 varchar(50), Add2 varchar(50)) << BusinessListBase>>

* foreign key relation between TblMastAddress.CustomerID = TblMastCustomer.ID is used

On then Basis of the structure how can i write the following code..?

 

1 CustomerList customerList = CustomerList.New();

2 Customer customer= customerList.AddNew();

3 customer.Name="New Customer";

4 Address address =customer.AddressList.New().AddNew();

5 address.City = "New City";

6 address.State = "New State";

7 customerList.Save();

 

because the code is throwing foreign key relation error..

( i found the absence of address.CustomerID = customer.ID (foreign key relation in  property, but i can't  use this untill the Customer Object get saved (because Customer.ID is auto generated by database) and i can execute only  customerList.Save()  

*code to save customer only and get that object and after that create new address and then save it ... i think this is not a good practice...?

So, can we auto (basis on .edmx file )maintain .tt for the Foreign key in Child_Insert..? ( i tried but not able to get relative properties object means customer.Id and adderess.CustomerID)

 

 

pls Help.

 

Thanks & Regards,

Akhil

 


 

Sep 13, 2010 at 12:49 PM
Edited Sep 13, 2010 at 12:49 PM

 

also

i got

NavigationProperty property = new NavigationProperty()

but how can i access the relative key property in the .tt

..?