Entity Framework Code First ile Model First arasında küçük bir metod farkı var. DeleteObject Metodu bulunmuyor. Sizde productId ye göre ürün silmek istiyorsanız aşağıdaki kodları uyarlayabilirsiniz. Kolay Gelsin :)
public bool DeleteProductAccordingToID(int id)
{
using (DbContext db= new DbContext())
{
var result = db.tbl_Product.Where(p=>p.CategoryID==id).ToList(); result.ForEach(i=>db.tbl_Product.Remove(i));
return db.SaveChanges() > 0;
}
}
public bool DeleteProductAccordingToID(int id)
{
using (DbContext db= new DbContext())
{
var result = db.tbl_Product.Where(p=>p.CategoryID==id).ToList(); result.ForEach(i=>db.tbl_Product.Remove(i));
return db.SaveChanges() > 0;
}
}