问题描述
我已经设置非常相似,微风随附示例应用程序。这是我的API控制器的code:
I have setup very similar to breeze sample application which comes in sample nuget. This is the code of my api controller:
[JsonFormatter, ODataActionFilter]
public class WorkOrdersController : ApiController
{
readonly EFContextProvider<WorkOrdersContext> _contextProvider =
new EFContextProvider<WorkOrdersContext>();
public WorkOrdersController()
{
// I was thinking this may be the cause of the issue
this._contextProvider.Context.Configuration.ProxyCreationEnabled = false;
}
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
return _contextProvider.SaveChanges(saveBundle);
}
[HttpGet]
public IQueryable<WorkOrder> WorkOrders()
{
return _contextProvider.Context.WorkOrders;
}
}
我遇到的问题是,当我尝试通过工作订单
操作执行查询,我得到500 - 内部服务器错误,这是响应的有效载荷:
The problem I'm having is when I try to perform query over WorkOrders
action, I get 500 - Internal server error, and this is the payload of response:
{"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"The action 'WorkOrders' on controller 'WorkOrders' with return type 'System.Collections.Generic.List`1[[WorkOrders.Domain.Models.WorkOrder, WorkOrders.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot support querying. Ensure the type of the returned content is IEnumerable, IQueryable, or a generic form of either interface.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.QueryableAttribute.ValidateReturnType(Type responseContentType, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)\r\n at System.Web.Http.Tracing.Tracers.ActionFilterAttributeTracer.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"}
工作订单是Dbset上下文:
WorkOrders is Dbset on context:
public DbSet<WorkOrder> WorkOrders { get; set; }
我也试图明确它铸造到IQueryable的,没有任何变化:
I have also tried explicitly casting it to IQueryable, with no change:
[HttpGet]
public IQueryable<WorkOrder> WorkOrders()
{
return (IQueryable<WorkOrder>)_contextProvider.Context.WorkOrders;
}
这对我的作品的唯一事情是:
The only thing that works for me is:
[HTTPGET]
公共IEnumerable的工作订单()
{
返回_contextProvider.Context.WorkOrders.AsEnumerable();
}
[HttpGet] public IEnumerable WorkOrders() { return _contextProvider.Context.WorkOrders.AsEnumerable(); }
本,但会导致另一个问题,我在客户端,在的描述。
This, however causes another problem for me on the client side, described in this question.
推荐答案
在这里只是一个猜测,但你可以尝试使用最新的微风(V 0.82.1)具有以下属性。
Just a guess here, but can you try using the latest breeze (v 0.82.1) with the following attribute.
[BreezeController]
[BreezeController]
而不是这些
[JsonFormatter,ODataActionFilter]
[JsonFormatter, ODataActionFilter]
新[BreezeController]属性是其他两个完全替代,避免了其他一些问题。
The new [BreezeController] attribute is a complete replacement for the other two and avoids some other issues.
这篇关于微风的WebAPI控制器'不能支持查询“过度DbSet错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!