做这样的事情的最佳方式是什么:
var existingEntities = new []
{
new Product {Name = "Name1", Count = 10},
new Product {Name = "Name2", Count = 20}
};
using (var context = new ProductContext())
{
// attach several entities
context.SaveChanges();
}
我应该迭代每个实体并将其设置为State = EntityState.Modified?
答案 0 :(得分:0)
是的,迭代并设置
context.Entry(existingproduct).State = EntityState.Modified;
是要走的路。