0
votes

I am trying to run a query with a filter on a string column, but at runtime a few filter values (e.g. 'PO Box 27') result in failed queries. When trying to filter using my query fails with the error message: "The string 'PO Box 27' is not a valid TimeSpan value."

Code: var crmAccountsQuery = EntityQuery .from('crmAccountEFs') .where(breeze.Predicate.create('address1_Line1', 'eq', 'abc'));

return manager.executeQuery(crmAccountsQuery)
    .then(function (data) {
        crmAccountsObservable(data.results);
        return;
    })
    .fail(queryFailed);

The breeze.js on the client builds a url like:

http://localhost:49800/breeze/BreezeDb/crmAccountEFs?$filter=(Address1_Line1%20eq%20time'PO%20Box%2027')

The time typing is completely wrong.

Edit: related to: BreezeJS malformed OData query Url when using "startsWith"

1

1 Answers

0
votes

For others benefit I found the unexpected answer. Turns out the case of the 'from' entityType was wrong (CrmAccountEFs), but no error is raised. The server handles case change, and the client silently falls back to an anonymous type (as the code is attempting to cope with Projection Queries). This is in EntityQuery._getFromEntityType().

The consequences are when the Query is run, the resource name is not resolved to an entityType. Instead it is given an anonymous entityType, which means the column's type has to be inferred from it's value. In my case a leading 'P' meant it is typed as Time. But when the resulting url is read by the server it fails trying to cast it to the correct type.

//var query = breeze.EntityQuery.from("Todos");    //Ok

//wrong case => entityType = Anonymous => column's type inferred from value
var query = breeze.EntityQuery.from("todos");    //Error 

http://jsfiddle.net/rockresolve/C4A

Breeze Devs: This subtle error is difficult to track down (and may be raised by other string type inferences). Is it possible to have EntityQuery by default expect a resourceName which is a valid entityType, and only allow an Anonymous type when an explicit parameter is set.