3

私はDynamicssdkdllのバージョン5.0.9689.2165を使用しており、Dynamics Onlineアカウントから(両方ともカスタムプロパティです。プロジェクトで生成されたプロキシクラスを使用してこれらにアクセスします)未満Linq のすべてのアカウントを取得しようとしています。Account.XDateAccount.YDateDateTime

私はこの基本的な表現を持っています:

var accounts = myOrganizationServiceContext.CreateQuery<Account>().Where(a => a.XDate < a.YDate)

しかし、処理されると、以下の例外が発生します-サーバー上の2つのエンティティプロパティを比較できませんか?

System.InvalidOperationException occurred
  Message=variable 'a' of type 'Account' referenced from scope '', but it is not defined
  Source=System.Core
  StackTrace:
       at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
       at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
       at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
       at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
       at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node)
       at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.CompileExpression(LambdaExpression expression)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateExpressionToValue(Expression exp, ParameterExpression[] parameters)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateExpressionToConditionValue(Expression exp, ParameterExpression[] parameters)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereCondition(BinaryExpression be, FilterExpressionWrapper parentFilter, Func`2 getFilter, Boolean negate)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(String parameterName, BinaryExpression be, FilterExpressionWrapper parentFilter, Func`2 getFilter, List`1 linkLookups, Boolean negate)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereBoolean(String parameterName, Expression exp, FilterExpressionWrapper parentFilter, Func`2 getFilter, List`1 linkLookups, BinaryExpression parent, Boolean negate)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(String parameterName, BinaryExpression be, FilterExpressionWrapper parentFilter, Func`2 getFilter, List`1 linkLookups, Boolean negate)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereBoolean(String parameterName, Expression exp, FilterExpressionWrapper parentFilter, Func`2 getFilter, List`1 linkLookups, BinaryExpression parent, Boolean negate)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(QueryExpression qe, String parameterName, Expression exp, List`1 linkLookups)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetQueryExpression(Expression expression, Boolean& throwIfSequenceIsEmpty, Boolean& throwIfSequenceNotSingle, Projection& projection, NavigationSource& source, List`1& linkLookups)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetEnumerator[TElement](Expression expression)

私の電話でここにいた

InnerException:

4

1 に答える 1

4

これは、CRM Linq プロバイダーの制限を表しています (これもまた)。マイクロソフトあたり:

ここ
で、句の左側は属性名で、句の右側は値である必要があります。左辺を定数に設定することはできません。節の両側を定数にすることはできません。

Linq プロバイダーを使用して特定の問題を解決するには、全体AccountSetをメモリ内に収集し、結果に対して通常の Linq メソッドを使用して、目的の最終結果を取得する必要がある場合があります。

var accounts = myOrganizationServiceContext
    .CreateQuery<Account>()
    .Select(a => new { a.AccountId, a.XDate, a.YDate })
    .ToList();

var filteredAccounts = accounts
    .Where(a => a.XDate < a.YDate);
于 2012-08-10T13:49:53.813 に答える