简体   繁体   English

ASP 核心 3.1 API 与 EF 核心 5.0

[英]ASP Core 3.1 API with EF Core 5.0

I'm very interested by the new filtered feature in EF core 5.0 .我对EF core 5.0 中的新过滤功能非常感兴趣。 I updated my entity framework with Nuget however I still can't use Where after Include.我用 Nuget 更新了我的实体框架,但是在 Include 之后我仍然无法使用 Where。

Is it because my APIP is developed in NET Core 3.1?是不是因为我的 APIP 是在 NET Core 3.1 中开发的?

在此处输入图像描述

Thank you for your help谢谢您的帮助

Edit:编辑:

This is my csproj file:这是我的 csproj 文件: 在此处输入图像描述

The reason is because GrowerPayee is not a collection.原因是因为 GrowerPayee 不是一个集合。 Code below works fine, but try to filter the Setting and you will have the same problem下面的代码工作正常,但尝试过滤设置,你会遇到同样的问题

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

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

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