0

I have an error when i'm trying to use the ANY operator with Breezejs on OData service :

var query = breeze.EntityQuery.from("Orders")
              .where("orderLines", breeze.FilterQueryOp.Any, "quantity",  breeze.FilterQueryOp.GreaterThan, 50);

I'm getting the following error :

"TypeError: Cannot read property 'isAnonymous' of undefined
at proto._validate (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10334:27)
at Function.ctor.create (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10288:18)
at proto.validate (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10908:36)
at proto.validate (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10913:25)
at proto.toODataFragment (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10837:14)
at toFilterString (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:10011:27)
at proto._toUri (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:9991:35)
at proto.toQueryString (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:6380:26)
at proto.getUrl (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:14140:61)
at fn.executeQuery (http://localhost/app/bower_components/bower-breeze/breeze.debug.js:15073:34)".

This HTTP request works well :

http://localhost/api/service.svc/Orders?$filter=orderLines/any(ol:ol/quantity gt 50)

When I'm try to use metadata before execute the query I have the following error :

var query = breeze.EntityQuery.from("Orders").top(10);
manager.fetchMetadata().then(function () {
    return manager.executeQuery(query).fail(function (data) { 
        $log.error(data) 
    });
}).then(function (data) {
    $log.info(data);
});

Error: Unable to locate a 'Type' by the name: 'Order:#System.Data.Objects'. Be sure to execute a query or call fetchMetadata first.

Breeze seems to use the wrong namespace 'Order:#System.Data.Objects'. The right namespace is 'App.API.Context' like the exportMetadata function shows :

{
    "shortName": "Order",
    "namespace": "App.API.Context",
    "autoGeneratedKeyType": "Identity",
    ...
}

Thanks for your help !

nboukeffa
  • 127
  • 1
  • 9
  • The error indicates that an entity type can't be recognized. We don't know yet which entity type it is. Have you tried a simple query, such as retrieving only Orders or retrieving OrderLines and see if that works? – DenisK May 19 '14 at 18:40
  • Hi, I tried this request and it worked : `var query = breeze.EntityQuery.from("Orders").expand("orderLines").top(1);` – nboukeffa May 20 '14 at 14:45
  • Interesting. Now can you try querying just the `OrderLines` with a variation of `Where` clause as well as using the `quantity` property? – DenisK May 20 '14 at 18:09
  • It works: `var query = breeze.EntityQuery.from("OrderLines").where("quantity", breeze.FilterQueryOp.GreaterThan, 200).top(100);`. This query sends this HTTP request `http://localhost/api/service.svc/OrderLines?$filter=quantity gt 200&$top=100`. – nboukeffa May 21 '14 at 07:31
  • Hmm, this is really strange. I'd like to see how the client metadata looks like just before you execute the failing query. To do that, just put a breakpoint on your failing query and in the console, export the entityManager metadata by calling `entityManager.metadataStore.exportMetadata()`. This will serialize the metadata as strings to the console. You can share just the portion for Order and OrderLines definitions. – DenisK May 21 '14 at 19:20
  • I don't fetch metadata before executing the query so the exportMetadata is empty. I tried to use metadata with a simple query and I get another strange error... I'm updating the main post for more readability. Thanks for your help. – nboukeffa May 22 '14 at 12:54
  • This is starting to sound like a resource name issue where the resource name is not mapped to an entity type. See if this post can give you further clues on how to debug this. http://stackoverflow.com/questions/22666995/breeze-js-getting-error-trying-to-use-any-operator-error-unable-to-get-va. Notice the poster has the same exception message as well. – DenisK May 22 '14 at 18:55
  • Ok I found where the problem's come from :) I'm writing the resolution in few minutes. – nboukeffa May 26 '14 at 13:37
  • As it's mentioned in this post [link](http://blogs.msdn.com/b/writingdata_services/archive/2011/06/15/entity-framework-4-1-code-first-and-wcf-data-services.aspx), I used ObjectContext to define my service. With ObjectContext the service generates a wrong namespace in metadata (System.Data.Objects) that prevents BreezeJS to work. I replaced ObjectContext by MyContext and BreezeJS works much better. Thanks for your help ! – nboukeffa May 26 '14 at 14:47
  • It works much better but I still have an error when I'm using the any operator. BreezeJS send the HTTP Request Header DataServiceVersion:2.0 and the data service return this error : `Error: The DataServiceVersion '2.0' is too low for the request. The lowest supported version is '3.0'.;` – nboukeffa May 26 '14 at 14:50

0 Answers0