the new filtered feature in EF core 5.0对我很感兴趣。我使用Nuget更新了实体框架,但是在Include之后仍然无法使用Where。
是因为我的APIP是在NET Core 3.1中开发的?
感谢您的帮助
编辑:
答案 0 :(得分:0)
原因是因为GrowerPayee不是集合。 下面的代码工作正常,但是尝试过滤设置,您将遇到同样的问题
public class Organisation
{
public Guid Id { get; set; }
public string Name { get; set; }
public List<Location> Locations { get; set; }
public Setting Setting { get; set; }
}
public class Setting
{
public string ApiKey { get; set; }
}
public class Location
{
public Guid Id { get; set; }
public Guid OrganisationId { get; set; }
public Organisation Organisation { get; set; }
public string Name { get; set; }
}
public class Db : DbContext
{
public DbSet<Organisation> Organisations { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (var db = new Db())
{
var organisations = db.Organisations
.Include(x => x.Locations.Where(l => l.Name.Contains("ABC")))
.Where(o => o.Name.Contains("OOO"))
.ToArray();
}
}
}