IEnumerable.Where() を使用して WCF Data Service クライアント側プロキシから DataServiceQuery をフィルター処理する Expression を手動で作成しています。
public class EntityIdentity
{
public EntityIdentity(long id);
{
this.Id = id;
}
private long Id {get; private set;}
public override bool Equals(object obj)
{
return obj is EntityIdentity && this.Id == (obj as EntityIdentity).Id;
}
public override string ToString()
{
return this.Id.ToString();
}
}
public class Entity
{
public Entity()
{
this.Id = new EntityIdentity(0);
this.Name = null;
}
public EntityId Id { get; set; }
public string Name { get; set; }
}
上記のクラスを考慮して、次の where と同等の式を作成していますEntityIdentity targetId = new EntityIdentity(1)
。
container.Entities.Where(e => e.Id.Equals(targetId));
このクエリを解決しようとすると、LINQ-to-URI トランスレーターが次の例外をスローします。
{System.NotSupportedException: Could not convert constant 1 expression to string.
at System.Data.Services.Client.ExpressionWriter.VisitConstant(ConstantExpression c)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.VisitOperand(Expression e, Nullable`1 parentType, Nullable`1 childDirection)
at System.Data.Services.Client.ExpressionWriter.VisitBinary(BinaryExpression b)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.VisitOperand(Expression e, Nullable`1 parentType, Nullable`1 childDirection)
at System.Data.Services.Client.ExpressionWriter.VisitBinary(BinaryExpression b)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.Visit(Expression exp)
at System.Data.Services.Client.ExpressionWriter.Translate(Expression e)
at System.Data.Services.Client.ExpressionWriter.ExpressionToString(DataServiceContext context, Expression e, Boolean inPath, Version& uriVersion)
at System.Data.Services.Client.UriWriter.ExpressionToString(Expression expression, Boolean inPath)
at System.Data.Services.Client.UriWriter.VisitQueryOptionExpression(FilterQueryOptionExpression fqoe)
at System.Data.Services.Client.UriWriter.VisitQueryOptions(ResourceExpression re)
at System.Data.Services.Client.UriWriter.VisitResourceSetExpression(ResourceSetExpression rse)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.UriWriter.Translate(DataServiceContext context, Boolean addTrailingParens, Expression e, Uri& uri, Version& version)
at System.Data.Services.Client.DataServiceQueryProvider.Translate(Expression e)
at System.Data.Services.Client.DataServiceQuery`1.Translate()
at System.Data.Services.Client.DataServiceQuery`1.QueryComponents(ClientEdmModel model)
at System.Data.Services.Client.DataServiceRequest.CreateExecuteResult(Object source, DataServiceContext context, AsyncCallback callback, Object state, String method)
at System.Data.Services.Client.DataServiceRequest.BeginExecute(Object source, DataServiceContext context, AsyncCallback callback, Object state, String method)
at System.Data.Services.Client.DataServiceQuery`1.BeginExecute(AsyncCallback callback, Object state)
at System.Data.Services.Client.DataServiceQuery`1.BeginExecuteInternal(AsyncCallback callback, Object state)
at System.Data.Services.Client.DataServiceQuery.BeginExecute(AsyncCallback callback, Object state)
at ProAlign.ServerDataModule.Services.ModelSetQueryContext.<>c__DisplayClassa.<Execute>b__3()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()}
前述の「定数 1 式」は、targetId
変数の値を参照します。これは何を意味し、どうすればよいのでしょうか?