efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Explicit loading .Query() .Where clause not filtering in SQLite

Open SharePointRadi opened this issue 9 years ago • 1 comments

The following explicit loading of a child collection doesn't filter with a where clause:

 await _dbContext.Entry(project)
                .Collection(p => p.Assets)
                **.Query()
                .Where(asset=>asset.IsArchived == false)**
                .LoadAsync();

            // the following line must return false
            var hasArchivedAssets = project.Assets.Any(asset => asset.IsArchived == true);

The model is a simple relationship, however the child object is an abstract class:

    public class Project
    {
        public List<Asset> Assets { get; set; }
    }

    public abstract class Asset
    {
        public bool IsArchived { get; set; }
    }

I am using SQLite as a database.

Steps to reproduce

Full solution here: https://github.com/OneBitSoftware/TeamStore/blob/master/src/TeamStore.Keeper/Services/AssetService.cs#L273

Further technical details

EF Core version: 2.0.0 Database Provider: SQLite Operating system: Windows IDE: Visual Studio 2017 15.4

SharePointRadi avatar Dec 03 '17 15:12 SharePointRadi

Actually this is working as expected. My tests we're wrong. (Project was already populated with Assets).

SharePointRadi avatar Dec 03 '17 16:12 SharePointRadi