public partial class CommunityPromotion
{
public bool IsNew
{
get
{
return this.ID <1;
}
}
public bool isDeleted { get; set; }
}
//create a partial class for the database context and extend an interface that defines custom methods
public partial class DatabaseDataContext : IPromotionRepository
{
public void Save(Promotion promotion)
{
if (promotion.ID < 1) // if its a new promotion just insert it
{
this.Promotions.InsertOnSubmit(promotion);
}
else // if its an update to a promotion... check to see if any of the nested objects are marked as new or for delete
{
// this grabs all of the promotion objects that are new and inserts them
this.CommunityPromotions.InsertAllOnSubmit(promotion.CommunityPromotions.Where(a => .IsNew));
this.CommunityPromotions.DeleteAllOnSubmit(promotion.CommunityPromotions.Where(a => a.isDeleted));
}
this.SubmitChanges();
}
}