Reputation: 242
I am using a simple repository pattern and have objects with a LazyList such as:
public class Promotion
{
public int Id { get; set; }
public string Name { get; set;}
public LazyList<Site> TargetSites { get; internal set; } // implemented as a LazyList
}
This works great for getting the items but I'm wondering what is usual to do for saving the items?
To persist a promotion I then need to save the list of TargetSites only if they were loaded in the first place. Is this the usual pattern with lazy loaded items? I can find lots of info on lazy loading but very little on persisting the resulting modifications to the lazy loaded objects.
Upvotes: 4
Views: 235
Reputation: 4001
As long as the relationship exists in your data model a call to context.SubmitChanges should save the parent object as well as the child objects if they are loaded and have changed. That's the beauty of L2S (and other orms).
Upvotes: 1