简体   繁体   中英

ASP Core 3.1 API with EF Core 5.0

I'm very interested by the new filtered feature in EF core 5.0 . I updated my entity framework with Nuget however I still can't use Where after Include.

Is it because my APIP is developed in NET Core 3.1?

在此处输入图像描述

Thank you for your help

Edit:

This is my csproj file: 在此处输入图像描述

The reason is because GrowerPayee is not a collection. 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();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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