efcore
efcore copied to clipboard
Explicit loading .Query() .Where clause not filtering in SQLite
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
Actually this is working as expected. My tests we're wrong. (Project was already populated with Assets).