Skip to content

Commit

Permalink
修复Include错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Kation committed Sep 30, 2017
1 parent 63a1004 commit b677680
Showing 1 changed file with 8 additions and 9 deletions.
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Wodsoft.ComBoost.Data.Entity.Metadata;

Expand Down Expand Up @@ -38,13 +39,7 @@ public Task<int> CountAsync(IQueryable<T> query)
{
return InnerContext.CountAsync(query.Unwrap<T, M>());
}

protected virtual Expression<Func<M, TResult>> WrapExpression<TResult>(Expression<Func<T, TResult>> expression)
{
ExpressionWrapper<T, M> wrapper = new ExpressionWrapper<T, M>();
return (Expression<Func<M, TResult>>)wrapper.Visit(expression);
}


public T Create()
{
return InnerContext.Create();
Expand Down Expand Up @@ -107,8 +102,12 @@ public void UpdateRange(IEnumerable<T> items)

public IQueryable<T> Include<TProperty>(IQueryable<T> query, Expression<Func<T, TProperty>> expression)
{
var newExpression = WrapExpression(expression);
return InnerContext.Include(query.Unwrap<T, M>(), newExpression).Wrap<T, M>();
ExpressionWrapper<T, M> wrapper = new ExpressionWrapper<T, M>();
LambdaExpression newExpression = (LambdaExpression)wrapper.Visit(expression);
var propertyType = newExpression.Type.GetGenericArguments()[1];
var queryable = query.Unwrap<T, M>();
queryable = (IQueryable<M>)InnerContext.GetType().GetMethod("Include").MakeGenericMethod(propertyType).Invoke(InnerContext, new object[] { queryable, newExpression });
return queryable.Wrap<T, M>();
}

public async Task<T> GetAsync(object key)
Expand Down

0 comments on commit b677680

Please sign in to comment.