Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze $filter projections
    text
    copied!<p>I am having an issue trying to filter data because breeze is adding the $filter clause at the end of the URL and the WCF\odata service is throwing filter cannot be after select clause.</p> <pre><code> public IQueryable&lt;order&gt; Orders() { string owner= Membership.GetUser(Thread.CurrentPrincipal.Identity.Name).owner; IQueryable&lt;Consigne&gt; q = this.db.Consignes // .AddQueryOption("Dest", dest) .Where(x =&gt; x.Owner == owner) .Select(f =&gt; new order{ Name= f.Name, Address1 = f.Address1, Address2 = f.Address2, Address3 = f.Address3 }); return q; } </code></pre> <p>I'm already limiting the result set with the server side Where clause and limiting the fields with the Select projection. If I remove these and let breeze have full control of Where\Select then I blow my security model allowing the js code to have control.</p> <p>I realize this isn't truly a Breeze issue and more of an odata issue but how are others dealing with this? Do you just give up on iQueryable and just create a webapi and pass back json? If so, then i'm reinventing the wheel since i also need to deal with skip\take and orderby.</p> <p>Appreciate the suggestions :) Kind Regards, Mike </p> <hr> <p>Solved</p> <p>I've found there is no way for WCF to pass as iQueryable without loosing the TotalCount. WCF is returning a QueryOperationResponse which I can pass back to breeze, but once cast to an object by breeze there is no way I've found in Breeze's QueryHelper.WrapResults to cast the dynamic type back to a usable object to retrieve the extended TotalCount properties. </p> <p>QueryHelper will execute the query</p> <pre><code>queryResult = Enumerable.ToList((dynamic)queryResult) </code></pre> <p>but</p> <pre><code>request.Properties.TryGetValue("MS_InlineCount", out tmp) </code></pre> <p>fails because of the wrong underlying object.</p> <p>My solution was to Execute the query in my BreezeController and wrap the rows and TotalCount in an array as Breeze would have. Then I can pass the array back as type QueryResult and breeze will serialize to JSON to the client.</p> <pre><code> public QueryResult Consignees(string filter, int skip, int take) { WcfService.Context context = new WcfService.Context(new System.Uri(System.Configuration.ConfigurationManager.AppSettings["URI"])); //Main Table System.Data.Services.Client.DataServiceQuery&lt;WcfService.Consigne&gt; qMain = context.Consignes.IncludeTotalCount(); //Projected Table System.Data.Services.Client.DataServiceQuery&lt;Consigne&gt; qProj = (System.Data.Services.Client.DataServiceQuery&lt;Consigne&gt;)qMain .Where(x =&gt; x.Refname.StartsWith(filter)) .Skip(skip) .Take(take) .Select(f =&gt; new Consigne { Refname = f.Refname, Consignee = f.Consignee, Address1 = f.Address1, Address2 = f.Address2, Address3 = f.Address3 }); System.Data.Services.Client.QueryOperationResponse&lt;Consigne&gt; qResult= qProj.Execute() as System.Data.Services.Client.QueryOperationResponse&lt;Consigne&gt;; QueryResult queryResult = new QueryResult() { Results = qResult.ToList(), InlineCount = qResult.TotalCount }; return queryResult; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload