与RemoveRange批量删除行() [英] Bulk deleting rows with RemoveRange()

查看:274
本文介绍了与RemoveRange批量删除行()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从表中删除多行



在常规SQL服务器,这将是简单所示:

  DELETE FROM表
,其中
TABLE.COLUMN ='SomeRandomValue'
和Table.Column2 ='AnotherRandomeValue'

在实体框架6,他们推出的 RemoveRange()方法。结果
然而,当我使用它,而不是删除使用我提供的where子句行,实体框架查询数据库获得匹配where子句的所有行,并使用其主键由一个删除它们。



这是的EntityFramework的电流限制?
或我使用 RemoveRange()错了?



以下是我如何使用 RemoveRange()

  db.Tables.RemoveRange(
分贝。表
。凡(_ => _.Column =='SomeRandomValue'
和;&安培; _.Column2 =='AnotherRandomValue')
);


解决方案

我想我们到达这里EF的限制。
有时候,你只需要使用的 ExecuteSqlCommand 保持高性能。


I am trying to delete multiple rows from a table.

In regular SQL Server, this would be simple as this:

DELETE FROM Table
WHERE
    Table.Column = 'SomeRandomValue'
    AND Table.Column2 = 'AnotherRandomeValue'

In Entity Framework 6, they have introduced RemoveRange() method.
However, when I use it, rather than deleting rows using the where clauses that I provided, Entity Framework queries the database to get all rows that match the where clauses and delete them one by one using their primary keys.

Is this the current limitation of EntityFramework? Or am I using RemoveRange() wrong?

Following is how I am using RemoveRange():

db.Tables.RemoveRange(
    db.Tables
        .Where(_ => _.Column == 'SomeRandomValue'
            && _.Column2 == 'AnotherRandomValue')
);

解决方案

I think we reached here a limitation of EF. Sometimes you just have to use ExecuteSqlCommand to stay performant.

这篇关于与RemoveRange批量删除行()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆