Breeze扩展错误

时间:2013-11-26 21:25:24

标签: breeze

不确定使用Breeze是否可行,但我们需要从2个不同的来源返回IQueryable

我们的业务逻辑从我们的控制器操作调用,以查看某些数据是否存储在数据库中,如果是,则从使用IQueryable的存储库返回EFContextProvider

否则,会创建一个包含默认数据的List<T>并转换为IQueryable,然后返回。

在客户端,我们的查询包含.expand,以确保使用所需数据填充导航属性。

IQueryable来自EF时,此功能正常,但在创建List<T>时崩溃并出现以下错误:

{"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"'System.Linq.EnumerableQuery<MyObject>' does not contain a definition for 'Include'","ExceptionType":"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException","StackTrace":"   at CallSite.Target(Closure , CallSite , Object , String )\r\n   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)\r\n   at Breeze.WebApi.QueryHelper.<>c__DisplayClass14.<ApplyExpand>b__11(String expand)\r\n   at System.Collections.Generic.List`1.ForEach(Action`1 action)\r\n   at Breeze.WebApi.QueryHelper.ApplyExpand(IQueryable queryable, String expandsQueryString)\r\n   at Breeze.WebApi.QueryHelper.ApplySelectAndExpand(IQueryable queryable, NameValueCollection map)\r\n   at Breeze.WebApi.BreezeQueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\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)"}

这是Breeze的问题(我们目前使用的是1.4.2),还是我做错了?

1 个答案:

答案 0 :(得分:0)

我认为在这种情况下你最好的选择是从客户端移除'expand'并将其移动到服务器(作为Include)。像这样:

[HttpGet]
public IQueryable<Customer> Customers(someCriteria) {
  if (... haveData ...) {
      return ContextProvider.Context.Customers.Include("Orders");
  } else {
      return DefaultCustomerList.AsQueryable()
  }
}