English 中文(简体)
WCF 数据服务:多重参数要求
原标题:WCF Data Services: request by multiple parameters

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));
            }
最佳回答

• 整整条,以示和使用<条码>。 由于我知道你不能只增加部分条件——必须从<条码><<>><>/条码>开始,该代码只界定了一套操作人员。 由于无法使用<代码> 如果 是你询问中的条件,则必须在<代码>上添加整个条件:

<代码> 任何都确保你使用正确的CTP(btw. CTP不准备释放)。 http://blogs.msdn.com/b/astoriateam/archive/06/30/announcing-wcf-data-services-june-2011-ctp-for-net4-amp-sl4.aspx”rel=“nofollow” (2011年6月,CTP/a)。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签