public class TestDirectorySearch : DataService<TestDirectoryEntitIEs>{ public static voID InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*",EntitySetRights.AllRead); config.SetEntitySetPageSize("*",50); config.UseVerboseErrors = true; config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V3; }}
我的edmx有以下几行:
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/Metadata">
当我尝试执行以下查询时,指出当MaxProtocolVersion小于’3.0’时,不支持“方法’OfType’.”
from test in context.Tests.OfType<OrderableTest>() where test.TestRevisionID.Equals(mmt.RevisionID) select new { Reflex = test.ReflexTest,ShipTemp = (test.SpecimenTemperature == null) ? null : test.SpecimenTemperature.displayDescription }).FirstOrDefault();
如果我检查上下文的MaxProtocolVersion,则将其设置为v2.在什么时候失败了?我该怎么做才能正确设置?
确切的错误:
{“当MaxProtocolVersion小于’3.0’时,不支持’OfType’方法.”}
请求的堆栈跟踪:
at System.Data.Services.ClIEnt.ResourceBinder.AnalyzeOfType(MethodCallExpression mce,DataServiceProtocolVersion maxProtocolVersion)at System.Data.Services.ClIEnt.ResourceBinder.VisitMethodCall(MethodCallExpression mce)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.DataServiceAlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.VisitExpressionList(ReadonlyCollection`1 original)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.VisitMethodCall(MethodCallExpression m)at System.Data.Services.ClIEnt.ResourceBinder.VisitMethodCall(MethodCallExpression mce)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.DataServiceAlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.ResourceBinder.AnalyzeProjection(MethodCallExpression mce,SequenceMethod sequenceMethod,Expression& e)at System.Data.Services.ClIEnt.ResourceBinder.VisitMethodCall(MethodCallExpression mce)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.DataServiceAlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.VisitExpressionList(ReadonlyCollection`1 original)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.VisitMethodCall(MethodCallExpression m)at System.Data.Services.ClIEnt.ResourceBinder.VisitMethodCall(MethodCallExpression mce)at System.Data.Services.ClIEnt.AlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.DataServiceAlinqExpressionVisitor.Visit(Expression exp)at System.Data.Services.ClIEnt.ResourceBinder.Bind(Expression e,DataServiceContext context)at System.Data.Services.ClIEnt.DataServicequeryProvIDer.Translate(Expression e)at System.Data.Services.ClIEnt.DataServicequery`1.Translate()at System.Data.Services.ClIEnt.DataServicequery`1.Execute()at System.Data.Services.ClIEnt.DataServicequery`1.GetEnumerator()at System.linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)at System.Data.Services.ClIEnt.DataServicequeryProvIDer.ReturnSingleton[TElement](Expression Expression)at System.Data.Services.ClIEnt.DataServicequeryProvIDer.Execute[TResult](Expression Expression)at System.linq.queryable.FirstOrDefault[TSource](Iqueryable`1 source)at TDMixBLL.TestDirectoryServiceHandler.PopulateOrderableTestInfo(MonitoredMixTest mmt) in C:\Dev\TDMix\ANSR - TDMix\TDMix2\TDMixBLL\TDMixBLL\TestDirectoryServiceHandler.cs:line 161at TDMixBLL.TestDirectoryServiceHandler.PopulateTestInfo(MonitoredMixTest test) in C:\Dev\TDMix\ANSR - TDMix\TDMix2\TDMixBLL\TDMixBLL\TestDirectoryServiceHandler.cs:line 124at TDMixBLL.TestDirectoryServiceHandler.GetTest(Int64 testRevisionID) in C:\Dev\TDMix\ANSR - TDMix\TDMix2\TDMixBLL\TDMixBLL\TestDirectoryServiceHandler.cs:line 112at TDMixBLL.TestDirectoryServiceHandler.PopulateTests(List`1 teststopopulate) in C:\Dev\TDMix\ANSR - TDMix\TDMix2\TDMixBLL\TDMixBLL\TestDirectoryServiceHandler.cs:line 66at TDMix2.Tests.TestRetrIEvalTests.TestPopulate() in C:\Dev\TDMix\ANSR - TDMix\TDMix2\TDMix2.Tests\TestRetrIEvalTests.cs:line 38解决方法 这是客户端上的错误. DataServiceContext必须用V3构造,以支持V3功能(如OfType). DataServiceContext有一个新的构造函数重载,它接受MaxProtocolVersion参数.确保使用它并传入V3. 总结
以上是内存溢出为你收集整理的c# – WCF数据服务:尽管服务设置为v3,但MaxProtocolVersion设置为v2.结束OfType()的投掷错误全部内容,希望文章能够帮你解决c# – WCF数据服务:尽管服务设置为v3,但MaxProtocolVersion设置为v2.结束OfType()的投掷错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)