Vikas Singhal
Vikas Singhal

Reputation: 836

Best way to create bulk entities in BreezeJS?

I am using a local JSON file to create entities in Breeze JS like this (inside a for loop).

var newCust = manager.createEntity('Clients', clients[i]);

Is there another way to do bulk insert with faster import times?

Upvotes: 0

Views: 146

Answers (2)

Jonathan
Jonathan

Reputation: 245

What part of the app lifecycle are these entities created? If an end-user is creating many entities thru the UI I'm not aware of making the bulk creation any faster than the way you have written. The createEntity() method doesn't accept or output an array of entities.

If you're loading these entities on start-up and trying to improve the performance of Page_Load, I think the proper way to do to this would be to create a Lookups service that provided a JSON object of the entities, calling this service, and using exportEntities() to save the entities to a local file. You can then store this on the server and provide it to the client in a bundle or < script> tag, using importEntities() to load in the entities. You would want some versioning rules on this file to ensure the client has the most up-to-date entities. By the way this would allow the browser to cache your lookups. (I haven't done this front-to-end yet but will soon as my application has a lot of Lookups).

In any case, I'm not aware of any way to get around the time it takes Breeze to instantiate and begin tracking these entities once the JSON data is on the client.

Upvotes: 0

Nathan Fisher
Nathan Fisher

Reputation: 7941

Just a thought. No idea if it would work but what about using breeze query to get the data in.
something like:-

var query = breeze.EntityQuery.from('file:///c:/temp/myfile.json');
return manager.executeQuery(query).then(function (data){
    return data.results;
});

Upvotes: 1

Related Questions