I m trying to generate a request to my WCF service. I need to query WCF by datetime parameter OR by Ids.
I mean in the final result I want to get the url like myservice.svc/MyObjects()?$filter=CreateDate ge datetime datecomeshere or Id eq 3 or Id eq 45 or Id eq 112
The problem is that I have a collection of ids on client side and one date variable. So how can I generate this kind of request to WCF?
Here is the code that I have right now:
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>;
}
This code throws an exception that max protocol version should be not less than 3.0 and Any method is not supported. But I have version 3.0
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
我也试图解决这一问题,执行这一守则,但在此情况下,我只想回去:
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));
}