Pregunta

I've got only client side Metadatstore:

initialize = (metadataStore) => {
    metadataStore.addEntityType({
        shortName: "AppsListHelper",
        namespace: NFL.settings.entityNamespace,
        dataProperties: {
            Path: { dataType: "String" },
            Title: { dataType: "String", isPartOfKey: true },
            Author: { dataType: "String" },
            Description: { dataType: "String" },
            ImageUrl: { dataType: "String" },
            IsFavourite: { dataType: "Boolean" },
            AppTypeName: { dataType: "String", isPartOfKey: true },
            Departments: { dataType: "String" },
            AlwaysShownTo: { dataType: "String" },
            AvailableTo: { dataType: "String" },
            HasAccess: { dataType: "Boolean" },
            Keywords: { dataType: "String" }
        }
    });

    metadataStore.registerEntityTypeCtor('AppsListHelper', function () { this.IsMyApp = ko.observable(false); });
}

I want to add additional property 'IsMyApp' only for client side usage - in one of my GET method I set this property to 'true':

    querySucceded = (data) => {   
    ko.utils.arrayForEach(data.results, (item: m_application.Application) => {
        item.IsMyApp(true);
    });
    return this.apps(data.results);
}

Now I try to query local data via breeze manager, using query:

private getLocal = (resource) => {
    var query = this.EntityQuery.from(resource).where('IsMyApp', '==', 'true').toType("AppsListHelper");
    return this.breezeManager.executeQueryLocally(query);
}

but nothing happens (view is loaded but is blank), after remove line for 'where clause' it returns all data.

Any help will be appreciate :)

My more detailed scenario is as follow: I have 2 views: 'My Apps' and 'All Apps'. Since all entities are the same type 'AppsListHelper', after I received both lists with data from the server they are cached toogether - that caused same data being displayed on two views (its understood for me) when pulled from local cache. So as first solution I wanted to add additional flag 'IsMyApp' only on client side since I really don't need it on a server and distinguish data based on value of this flag for appropriate view.

¿Fue útil?

Solución

@PKad is correct that a Breeze query ignores unrecognized properties. You could filter the cached-query results as he suggests.

Unmapped properties is another option to consider. An unmapped property is "known to Breeze" but not mapped to your database and will not be persisted on the server. It is a client-only extension.

You can define an unmapped property when you define your metadata on the client or you can define it in a custom constructor and register that with the type.

Then you can query it as shown in the DocCode:entityExtensionTests test, "can query an unmapped property with cache query".

Otros consejos

You can only create queries for properties that Breeze knows about. In your situation you are adding the property onto the constructor but Breeze doesn't really know that you are doing it, just allowing you a method to do it. (if that makes any sense)

You are probably just looking to filter the array, so why not do a query for the objects that meet other criteria and then just filter them? This is probably not valid TypeScript but should show you the right way -

var filteredResults = ko.utils.arrayFilter(data.results, function (result) {
    return result.IsMyApp() === true;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top