I am using System.Linq.Dynamic.Core;
and the following extension method to access a DbSet dynamically by name and generate queries from strings.
This is extesion method:
namespace Microsoft.EntityFrameworkCore
{
public static partial class CustomExtensions
{
public static IQueryable Query(this DbContext context, string entityName) =>
context.Query(context.Model.FindEntityType(entityName).ClrType);
public static IQueryable Query(this DbContext context, Type entityType) =>
(IQueryable)((IDbSetCache)context).GetOrAddSet(context.GetDependencies().SetSource, entityType);
}
}
This is how I access the DbSet:
IQueryable<T> dbSet = (IQueryable<T>)_db.Query(entityName);
This works fine, I can build a query and then create a list but none of the nested entities load. It seems IQueryable
doesn't have a definition for Include()
. I can see include method if I access db context directly in normal fashion but not using this dynamic method.
How do I include nested entities using dynamic method?