New Posts New Posts RSS Feed: Entity manager cache not working
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Entity manager cache not working

 Post Reply Post Reply Page  <12
Author
pawel View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2012
Posts: 12
Post Options Post Options   Quote pawel Quote  Post ReplyReply Direct Link To This Post Topic: Entity manager cache not working
    Posted: 25-Oct-2012 at 6:53am
As a side note - if you are building a solution based on CodeCamper with Breeze, then remember to remove json camelCasing formatting. Remove the following lines from Alcance.Web.GlobalConfig.CustomizeConfig()
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();

If you leave this configuration Breeze will be unable to populate your objects with data.
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 24-Oct-2012 at 1:14pm
Ok, I was unable to reproduce the first part of your error (shown below). I do not have a copy of the "CodeCamper" database but I've run the same test with our test db ( a version of Northwind) and manager.getEntities returns an array that it the same length as data.results.length.  So I'm not sure what's going on there.

 var query = entityModel.EntityQuery.from("Categories");
 manager.executeQuery(query).then(function (data) {
        alert(data.results.length);  //this returns 45 results
        alert(manager.getEntities().length); // this returns 0 results. WHY????
 });

As for "executeQueryLocally", it can only execute if the entityManager cache already has data in it.  I cannot tell from your example, but is it possible that you are calling getByParentUrl before any call to getData has completed.   Your getData method is asynchronous whereas your getByParentUrl is not, so you need to make sure that your getData call completes before calling getParentUrl.

If you continue to have issues, can you post a copy of your server side controller?


Back to Top
mgkoko View Drop Down
Newbie
Newbie


Joined: 24-Oct-2012
Posts: 1
Post Options Post Options   Quote mgkoko Quote  Post ReplyReply Direct Link To This Post Posted: 24-Oct-2012 at 3:23am
Hi there,

I've been developing a SPA based on John Papa's example of code camper. I came across with breeze.js and I really want to use this rather than building my own client db context. So far it is OK, but like in code camper example I want to load some data from dataprimer and que the results as needed from local cache. but everytime I tried executeQueryLocally I got 'entityType is null' error. When I check getEntities() to see if I got the results in cached it returns blank but if I check data.results then there are results. my code is

define('dataservice.categories',
    ['jquery', 'underscore', 'ko', 'config', 'utils','breeze', 'store'],
    function ($, _, ko, config, utils, breeze, store) {

        var entityModel = breeze.entityModel,
            core = breeze.core;

        // configure Breeze for Knockout and Web API
        core.config.setProperties({
            trackingImplementation: entityModel.entityTracking_ko,
            remoteAccessImplementation: entityModel.remoteAccess_webApi
        });

        // service name is route to the Web API controller
        var serviceName = '/api/breeze';


        // manager is the service gateway and cache holder
        var manager = new entityModel.EntityManager(serviceName);

        var getData = function () {
            var query = entityModel.EntityQuery.from("Categories");
            manager.executeQuery(query).then(function (data) {
                alert(data.results.length);  //this returns 45 results
                alert(manager.getEntities().length); // this returns 0 results. WHY????
            });
        },
        getByParentUrl = function (url, results) {
            var query = entityModel.EntityQuery.from("Categories");
            query = query.where("Parent.FriendlyUrl", "==", null);
            manager.executeQueryLocally(query); //I think this is the line where I got 'entityType is null' error
        }

        return {
            getData: getData,
            getByParentUrl: getByParentUrl
        }

    });

Please let me know if you have any question
Thank you,
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down