简体   繁体   English

如何将HQL内部联接转换为LINQ联接

[英]How can I convert HQL inner join to LINQ join

How can I write this HQL in Linq: 如何在Linq中编写此HQL:

select a from A a
join a.childrenList b
where b = 1

childrenList is a list of enums which is not mapped to database by type but rather is saved with its integer value. childrenList是一个枚举列表,它没有按类型映射到数据库,而是以其整数值保存。

This HQL works fine but I want to write it in Linq. 这个HQL工作正常,但我想用Linq编写。 I cannot write something that can be compiled. 我不能写一些可以编译的东西。

I think you can do 我想你可以做

var results = 
    from a in db.Query<A>() 
    where a.childrenList.Any(b => b == (B)1)
    select a;

or, using chained methods: 或者,使用链接方法:

var results = db.Query<A>().Where(a => a.childrenList.Any(b => b == (B)1));

Regarding our comments above, I think you can drop the from A a in ... select a statements, because they are redundant. 关于上面的评论,我认为您可以from A a in ... select a语句,因为它们是多余的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM