带有EF Core 5.0的ASP Core 3.1 API

时间:2020-07-23 09:11:59

标签: c# asp.net-core entity-framework-core

the new filtered feature in EF core 5.0对我很感兴趣。我使用Nuget更新了实体框架,但是在Include之后仍然无法使用Where。

是因为我的APIP是在NET Core 3.1中开发的?

enter image description here

感谢您的帮助

编辑:

这是我的csproj文件: enter image description here

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();
        }
    }
}