In an application I’m letting a user define “template” for contract and then apply that contract template to multiple customers. Contract object has property LineItems that holds list of items. I have a one-to-many relationship defined between the two. Contract also has UserID property, but for the template contract its always 0. Then after the user is done creating the contract, he/she clicks save and I cycle through the selected customers and create new instance of the contract template, setting the UserID to corresponding value. But what Happens is, LineItems are only stored once, for the first contract. I tried copying LineItems from template contract to the new List and then assigning it to each new instance of the template, but no luck.
Is there a design pattern to achieve something similar (Cloning a LINQ to SQL entity with the child collection)?
P.S. I’m using CodeSmith generated PLINQO to SQL entities and the LineItems property of the Contract object is of System.Data.Linq.EntitySet type.
Duh, it seems that PLINQO to SQL entities have Clone method that deep clones them with related associations.
Problem solved