更新时间:2023-11-25 11:39:34
我认为 ExecuteSqlRaw
更适合您:
_context.Database.ExecuteSqlRaw("DELETE FROM Users WHERE Name = @p0", "John");
通常 Remove
和 RemoveRange
适用于您已经具有 Primary Key
(通常是 Id
)的情况对象,在这种情况下,您可以执行以下操作:
Generally Remove
and RemoveRange
are suitable for situations which you already have Primary Key
(usually Id
) of objects, in those cases you can do something like this:
_context.Users.Remove(new User {Id = id});