igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
297 stars 112 forks source link

Linq with variable expression throws exception #345

Closed sobolev88 closed 9 years ago

sobolev88 commented 9 years ago

I tried to run the following query:

Expression<Func<ArticleFeatureValue, bool>> featureValueFilter = v => firstValue.NumberValue >= v.NumberValue;

var accQuery =
    from article in DataContext.GetTable<Article>()
    where DataContext.GetTable<ArticleFeatureValue>().Where(v => v.ArticleID == article.ID && v.FeatureID == feature.ID).Any(featureValueFilter)
    select article;

var result = accQuery.Select(a => a.ID).ToArray();

It throws exception:

Не удалось привести тип объекта "System.Linq.Expressions.FieldExpression" к типу "System.Linq.Expressions.LambdaExpression".

Server stack trace: в BLToolkit.Data.Linq.Builder.AllAnyBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\AllAnyBuilder.cs:строка 22 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.cs:строка 167 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.GetSubQuery(IBuildContext context, MethodCallExpression expr) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 187 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.SubQueryToSql(IBuildContext context, MethodCallExpression expression) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 201 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.ConvertToSql(IBuildContext context, Expression expression, Boolean unwrap, Boolean convertEnum) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 786 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.ConvertPredicate(IBuildContext context, Expression expression) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 1257 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildSearchCondition(IBuildContext context, Expression expression, List1 conditions) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 2175 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildWhere(IBuildContext parent, IBuildContext sequence, LambdaExpression condition, Boolean checkForSubQuery) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.SqlBuilder.cs:строка 46 в BLToolkit.Data.Linq.Builder.WhereBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\WhereBuilder.cs:строка 18 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.cs:строка 167 в BLToolkit.Data.Linq.Builder.WhereBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\WhereBuilder.cs:строка 17 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.cs:строка 167 в BLToolkit.Data.Linq.Builder.SelectBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\SelectBuilder.cs:строка 35 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.cs:строка 167 в BLToolkit.Data.Linq.Builder.ExpressionBuilder.Build[T]() в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Builder\ExpressionBuilder.cs:строка 138 в BLToolkit.Data.Linq.Query1.GetQuery(IDataContextInfo dataContextInfo, Expression expr) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\Query.cs:строка 166 в BLToolkit.Data.Linq.ExpressionQuery1.GetQuery(Expression expression, Boolean cache) в d:\Externals\BLToolkitGitMine\Source\Data\Linq\ExpressionQuery.cs:строка 77 в BLToolkit.Data.Linq.ExpressionQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() в d:\Externals\BLToolkitGitMine\Source\Data\Linq\ExpressionQuery.cs:строка 149