llihp
llihp

Reputation: 3

Breeze expand error

Not sure if this is possible using Breeze, but we have a situation where we need to return an IQueryable from 2 different sources.

Our business logic called from our controller action checks to see if some data is stored within a database, if so an IQueryable is returned from the repository which uses the EFContextProvider.

Otherwise, a List<T> is created containing default data and turned into an IQueryable, which is then returned.

On the client side, our query contains .expand to ensure the navigation properties are populated with the required data.

This works fine when the IQueryable is coming from the EF, but crashes with the following error when creating the 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)"}

Is this an issue with Breeze (we're using 1.4.2 at present), or is it something I'm doing wrong?

Upvotes: 0

Views: 205

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

I think your best bet in this case in this case is remove the 'expand' from the client and move it the server (as an Include). Something like this:

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

Upvotes: 0

Related Questions