再现“DELETE NOT IN” 通过 LINQ/Subsonic 的 SQL 语句
我想做一些类似 DELETE FROM TABLE WHERE ID NOT IN (1,2,3) AND PAGEID = 9
我有一个 IDS 列表,但如果需要的话可以更改。 我不知道如何为 LINQ 解析器获取布尔结果。
我认为这就是 Subsonic 所期望的。
db.Delete(content => content.PageID == ID).Execute();
我不知道如何执行 NOT IN 语句。 我尝试过 List.Contains 方法,但有些不太正确。
更新:一种替代方法是:
var items = TABLE.Find(x => x.PageID == ID)'
foreach(var item in items)
{
item.Delete();
}
这对数据库的影响更大
I want to do something like DELETE FROM TABLE WHERE ID NOT IN (1,2,3) AND PAGEID = 9
I have a List of IDS but that could be changed if needs be. I can't work out how to get a boolean result for the LINQ parser.
Here is what Subsonic expects I think.
db.Delete(content => content.PageID == ID).Execute();
I can't work out how to do the NOT IN statement. I've tried the List.Contains method but something not quite right.
UPDATE: One alternative is to do:
var items = TABLE.Find(x => x.PageID == ID)'
foreach(var item in items)
{
item.Delete();
}
This hits the database a lot more though
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当你说“有些事情不太对劲”时,你到底是什么意思?
我希望这样写:
请注意,您需要对排除值数组而不是候选值调用
Contains
。 换句话说,不是说“项目不在集合中”,而是说“集合不包含项目”。When you say "something not quite right" what exactly do you mean?
I'd expect to write:
Note that you need to call
Contains
on the array of excluded values, not on your candidate. In other words, instead of saying "item not in collection" you're saying "collection doesn't contain item."尝试 .Contains:(
以上只是一个示例,可能需要根据您的具体情况进行一些修改)
Try .Contains:
(the above is just an example, might need some polishing for your specific situation)
我发现这确实有效,但不是通过 LINQ
我发现这确实有效,并且通过 LINQ - 但它多次访问数据库。
我想这可以在一次数据库命中中起作用,但我在 QueryVisitor::VisitUnary 中抛出异常
I have found that this works but its not via LINQ
I have found that this does work and via LINQ - however it hits the database multiple times.
This I imagine would work in one hit to the database but I get an exception thrown in QueryVisitor::VisitUnary