NHibernate Linq where 子句:集合中的值
我想知道我可以做一个接受集合的 where 子句吗?
List<string> myStrings = new List<strings> {"1", "2"};
session.Query<Table>().Where(x => x.Id == myStrings).ToList();
我基本上想从我的数据库表中获取与该查询中的所有内容匹配的所有行。
session.Query<Table>().Where(x => x.Id == myStrings[0]).ToList();
session.Query<Table>().Where(x => x.Id == myStrings[1]).ToList();
session.Query<Table>().Where(x => x.Id == myStrings[N]).ToList();
这就是我现在必须做的。我可能会在 for 循环中完成它,但这是很多查询,我宁愿只做一个查询。
或者我必须使用 nhibernate 创建查询语法
var query = "Select * From Where In (:Id)";
session.CreateQuery(query)SetParameter("Id",myStrings) // not sure if I have to something like .ExecuteUpdate(); but just for select instead
I am wondering can I do a where clause that takes in a collection?
List<string> myStrings = new List<strings> {"1", "2"};
session.Query<Table>().Where(x => x.Id == myStrings).ToList();
I basically want to get all rows from my db table that match everything in that query.
session.Query<Table>().Where(x => x.Id == myStrings[0]).ToList();
session.Query<Table>().Where(x => x.Id == myStrings[1]).ToList();
session.Query<Table>().Where(x => x.Id == myStrings[N]).ToList();
So thats what I would have to do right now. I would probably through that in a for loop but that is alot of queryies and I rather just do one query.
Or do I have to use the nhibernate create query syntax
var query = "Select * From Where In (:Id)";
session.CreateQuery(query)SetParameter("Id",myStrings) // not sure if I have to something like .ExecuteUpdate(); but just for select instead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在您的集合上使用 Any 或 All 扩展方法
you should use Any or All extension method on your collection