Saturday, March 12, 2011

How To delete Collection From Context in Entity Framework 4.0


To Delete All Object by using Entity Framework 4.0

To Delete All OrderDetails of Customer Object where OrderID=103

 var x = customerContext.OrderDetails.Where(c => c.OrderID == 103);
 customerContext.DeleteAll(x.ToList());
 customerContext.SaveChanges();

you have to defile DeleteAll method in a static class

namespace Application.Global
{

public static class GlobalMethods
    {
      public static void DeleteAll(this ObjectContext context, IEnumerable records)
       {
           foreach (T record in records)
           {
               context.DeleteObject(record);
           }
       }
    }

}



No comments:

Post a Comment

Mat Table Angular

Mat Table in Angular Mat table is used to display data . its a material designed styled data-table . For using Material Table MatTableMo...