Search code examples
javascriptbreeze

how to convert breeze entity to json


I know this question has been asked before and there is a very old post with some details however it is dated and there was some discussion to add this to breeze.

I am using angularJS and a telerik component which doesn't work with breeze entities, i would very much like to convert a breeze entity query list to simple json so that i can map it to my component.

I know there has been mention of ko.toJs() but i do not use knockout. Is there a better method to do this?

Thanks


Solution

  • Use the noTracking EntityQuery method:

    From the breeze API docs:

    noTracking()

    Returns a query with the 'noTracking' capability either enabled or disabled. With 'noTracking' enabled, the results of this query will not be coerced into entities but will instead look like raw javascript projections. i.e. simple javascript objects.

    var query = new EntityQuery("Customers")
      .take(20)
      .orderBy("CompanyName")
      .noTracking(true);