Question

I'm absolutely loving BreezeJS and was so surprised to see that my Enum values were being displayed as their text values and not their ordinal ones! What I would love to be able to do is, on the client side, open the MetadataStore, fetch the enumeration and modify it's textual properties for display purposes.

Is this currently possible? From my research it would appear not, but I'm wondering if there is perhaps a simple workaround. Everything I've tried has involved a large number of hacks and server-side attributes, but to no avail, or the solution just seemed overly complex and not worth the benefits.

Was it helpful?

Solution

Here is what I said about how to get the enum values from raw metadata in another SO comment.

The enum values are available in the metadata generated by EF and sent to a Breeze client. I agree Breeze should pick them up automatically and put them somewhere so you don't have to make a separate request for them or extract them from the raw metadata passed to the MetadataStore.fetchMetadata success callback. It's on our backlog.

Meanwhile, you'll have to get them by hand. There is a DocCode test that shows how:

/*********************************************************
* Can can get enum types from raw EF-generated metadata
* Related to feature request #2271: Extract enum values from server metadata
*************************************************************/
asyncTest("can get enum type from raw EF-generated metadata", function() {

    var serviceName = testFns.foosMetadataServiceName;
    var store = new breeze.MetadataStore();
    store.fetchMetadata(serviceName)
        .then(metaSuccess, metaFail).fail(handleFail).fin(start);

    function metaSuccess(rawMetadata) {
        ok(true, "foos metadata fetched");
        var enumType = rawMetadata.schema && rawMetadata.schema.enumType;
        if (enumType && enumType.name ==='Color') {
            var members = enumType.member;
            ok(members.length,
                "should have several members; members are: " + JSON.stringify(members));
        } else {
            ok(false, "metadata should have had one enumType, 'Color'.");
        }
    }

    function metaFail(error) {
        ok(false, "foos metadata fetch failed: " + error.message);
    }

});

OTHER TIPS

we're using Breeze with NHibernate and wand to do the same. Metadata generated for NHibernate are standard breeze Metadata and doesn't contain the Schema part. Any ideas how to do it?

edit: To fix our issue I added a list of all used enums in the metadata(like the structuralTypes node). Then we cache it on the client when the metadata are retrieved. https://github.com/lnu/breeze.server.net/commit/65ad687ad13c4dd9f4a6ab6a3ed09e407e2b58ec

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top