Is there way to use INSERT OR REPLACE statement in LINQ to Entites
Posted: Thu 27 Jul 2017 09:32
In SQLite there is INSERT OR REPLACE statement. The idea is that when a UNIQUE or PRIMARY KEY constraint violation happens, the REPLACE statement:
So is there way to use INSERT OR REPLACE statement in LINQ to Entites?
Because now I have to use the follwing approach:
Is it possible to implement it with one single Linq query?
- 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();