如何在EFCORE中查询结果,其中在DBSET集合中满足条件?
实体(简化)如下:
class A
{
public Guid ID { get;set; }
public string Name { get;set; }
public ICollection<B> Bs { get;set; }
}
class B
{
public Guid ID { get;set; }
public ICollection<C> Cs { get;set; }
}
class C
{
public Guid ID { get;set; }
public string Key { get;set; }
}
我想查询A类A级的所有关键属性等于“测试”。我试图做的是:
var as = await this._applicationDbContext.As
.Where(a=> a.Bs.Any(b => b.Cs.Any(c=> c.Key == 'test')))
.ToListAsync();
但是我什么也没收回。我知道我可以包含BS,然后包括CS,然后用代码进行操作,但是应该有一种在EF查询中进行的方法吗?
The entities (simplified) are as follows:
class A
{
public Guid ID { get;set; }
public string Name { get;set; }
public ICollection<B> Bs { get;set; }
}
class B
{
public Guid ID { get;set; }
public ICollection<C> Cs { get;set; }
}
class C
{
public Guid ID { get;set; }
public string Key { get;set; }
}
I want to query for all of class A where the Key Property of class C equals 'test'. What I tried to do is:
var as = await this._applicationDbContext.As
.Where(a=> a.Bs.Any(b => b.Cs.Any(c=> c.Key == 'test')))
.ToListAsync();
But I am not getting anything back. I know I could include Bs and then Cs and do it in code, but there should be a way to do it in the ef query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的查询应该起作用,无论如何尝试以下变体:
Your query should work, anyway try the following variant:
您需要使用
.include()
You need to use
.Include()