TransWikia.com

ASP Core 3.1 API with EF Core 5.0

Stack Overflow Asked by bibout182 on December 9, 2021

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?

enter image description here

Thank you for your help

Edit :

This is my csproj file:
enter image description here

One Answer

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

Answered by dariogriffo on December 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP