How can I do to call a unique SaveChanges to affect all changes in all repositories that I use?
Should I create a class that contains all repositories and a Save method?
What’s the best way to do it?
I’m trying this:
public ActionResult Create()
{
Product Product = new Product() { Id = 1, Name = "test", Amount = 1 };
if (_productService.Insert(Product))
{
context.SaveChanges();
return View();
}
return RedirectToAction("Index");
}
Is this correct?
The best way is called unit of work and it is generally wrapper class to your EF context which is passed to constructor of your repositories. You than call
Saveon this new class.