- First, delete the existing row that causes the constraint violation.
- Second, insert a new row.
So is there way to use INSERT OR REPLACE statement in LINQ to Entites?
Because now I have to use the follwing approach:
Code: Select all
var ExistingUser = MyDbContext.MyDbSet<User>.Where(e => e.Id == UpdatedUser.Id).FirstOrDefault();
if (ExistingUser == null)
MyDbContext.MyDbSet<User>.Add(UpdatedUser);
else
ExistingUser.Name = UpdatedUser.Name;
MyDbContext.SaveChanges();