【发布时间】:2011-09-08 03:24:56
【问题描述】:
我正在尝试向我的 WCF 服务生成一个请求。 我需要通过日期时间参数或 Ids 查询 WCF。
我的意思是在最终结果中我想获得类似的网址 myservice.svc/MyObjects()?$filter=CreateDate ge datetime'datecomeshere' 或 Id eq 3 或 Id eq 45 或 Id eq 112
问题是我在客户端有一组 id 和一个日期变量。 那么如何向 WCF 生成这种请求呢?
这是我现在拥有的代码:
var localEntityIds = DbConnection.ObjectContextConnection.GetEntitiesByDate<T>(DateToReplicate).Select(x => x.Id);
if (DateToReplicate > DateTime.MinValue)
{
expQuery =
Service.CreateQuery<T>(SetName).Where(
x => x.ReplicaInfo.CreateDate >= DateToReplicate ||
x.ReplicaInfo.ModifyDate >= DateToReplicate || localEntityIds.Where(y=>y ==x.Id).Any()) as DataServiceQuery<T>;
}
此代码抛出一个异常,即最大协议版本应不低于 3.0 并且不支持任何方法。 但我有 3.0 版
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
我也尝试通过实现此代码来解决这个问题,但在这种情况下 wcf 什么也不返回:
var localentities = DbConnection.ObjectContextConnection.GetEntitiesByDate<T>(DateToReplicate).Select(x => x.Id);
if (DateToReplicate > DateTime.MinValue)
{
expQuery =
Service.CreateQuery<T>(SetName).Where(
x => x.ReplicaInfo.CreateDate >= DateToReplicate ||
x.ReplicaInfo.ModifyDate >= DateToReplicate) as DataServiceQuery<T>;
}
foreach (var localentity in localentities)
{
expQuery = expQuery.AddQueryOption("or", string.Format("Id eq guid'{0}'", localentity));
}
【问题讨论】:
标签: c# wcf entity-framework wcf-data-services