I am having a problem trying to combine a where clause with an include in EntityFrameworkCore. This is how the class I am trying to do this for looks:
public partial class TEntity
{
public TEntity()
{
TData = new HashSet<TData>();
}
public decimal Id { get; set; }
publis string TypeName { get; set; }
public virtual ICollection<TData> TData { get; set; }
}
This is how I am trying to get all entities of a specific type:
List<TEntity> entityList = dbContext.TEntity.Include("TData").Where(x => x.Type == typeName).ToList();
How can I add a filter to this so the collection of TData
only contains specific entries based on my filter criteria?
Right now, it always returns all of the TData
entries for the entity but I need to add a filter so only the entries with a specific date are included. Otherwise, thousands of TData
entries are returned and the query takes forever to execute which is not acceptable.