Skip to content

Instantly share code, notes, and snippets.

@smitpatel
Created June 9, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smitpatel/634ea12e608682282e57ec53ed5abc4f to your computer and use it in GitHub Desktop.
Save smitpatel/634ea12e608682282e57ec53ed5abc4f to your computer and use it in GitHub Desktop.
New include overloads to support including navigations using lambda on derived types while querying base type
public static class EntityFrameworkQuerybleExtensions
{
#region Current
public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
this IQueryable<TEntity> source,
Expression<Func<TEntity, TProperty>> navigationPropertyPath)
where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, TPreviousProperty> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
#endregion
#region NewOverloads
public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TDerived, TProperty>(
this IQueryable<TEntity> source,
Expression<Func<TDerived, TProperty>> navigationPropertyPath)
where TEntity : class
where TDerived : TEntity
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TDerived, TProperty>(
this IIncludableQueryable<TEntity, TPreviousProperty> source,
Expression<Func<TDerived, TProperty>> navigationPropertyPath) where TEntity : class where TDerived : TPreviousProperty
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TDerived, TProperty>(
this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source,
Expression<Func<TDerived, TProperty>> navigationPropertyPath) where TEntity : class where TDerived : TPreviousProperty
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
#endregion
}
@divega
Copy link

divega commented Jun 9, 2017

@smitpatel, collection navigations are actually of type IEnumerable<TPreviousProperty> rather than ICollection<TPreviousProperty> in the actual code, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment