got rid of generic depedancy. :)

This commit is contained in:
David Lebée
2018-03-14 19:25:47 -05:00
parent c4a398a8cb
commit 18a3756f51
8 changed files with 160 additions and 156 deletions
@@ -11,19 +11,17 @@ namespace PoweredSoft.DynamicLinq.EntityFramework
{
public static class DbContextExtensions
{
private static readonly MethodInfo QueryMethod = typeof(DbContextExtensions)
.GetMethods(BindingFlags.Static | BindingFlags.Public)
.First(t => t.Name == "Query" && t.IsGenericMethod);
public static IQueryable Query(this DbContext context, Type pocoType, Action<WhereBuilderBase> callback)
public static IQueryable Query(this DbContext context, Type pocoType, Action<WhereBuilder> callback)
{
var method = QueryMethod.MakeGenericMethod(pocoType);
var invokeResult = method.Invoke(null, new object[] {context, callback});
var ret = invokeResult as IQueryable;
return ret;
var set = context.Set(pocoType);
var queryable = set.AsQueryable();
var builder = new WhereBuilder(queryable);
callback(builder);
var result = builder.Build();
return result;
}
public static IQueryable<T> Query<T>(this DbContext context, Action<WhereBuilderBase> callback)
public static IQueryable<T> Query<T>(this DbContext context, Action<WhereBuilder> callback)
where T : class
{
var query = context.Set<T>().AsQueryable();
@@ -31,10 +29,10 @@ namespace PoweredSoft.DynamicLinq.EntityFramework
return query;
}
public static IQueryable Where(this DbContext context, Type pocoType, Action<WhereBuilderBase> callback)
public static IQueryable Where(this DbContext context, Type pocoType, Action<WhereBuilder> callback)
=> context.Query(pocoType, callback);
public static IQueryable<T> Where<T>(this DbContext context, Action<WhereBuilderBase> callback)
public static IQueryable<T> Where<T>(this DbContext context, Action<WhereBuilder> callback)
where T : class => context.Query<T>(callback);
}
}