bparcels
bparcels

Reputation: 31

Deep expand not working, despite [BreezeQueryable(MaxExpansionDepth = 100)]

First off, I really have to thank the devs so much... Breeze is absolutely fantastic, and I can't thank you enough for your hard work!

I've been using Breeze with EF (latest Breeze, latest EF) for a while now, and after some DB changes, I'm now forced to query for a fourth layer of objects... At first, I hit the error that the MaxExpansionDepth was reached, but as per a few questions/answers on SO, I found the [BreezeQueryable(MaxExpansionDepth = x)] attribute. I have applied this attribute to the relevant query function on the controller, which eliminated the error... However, the data at that fourth level still does not fill.

I have successfully retrieved the data in question with a specific query (based on the key of the 4rth level data), and everything works well when playing on the server side... Relationships work properly etc... The troublesome query is below:

function getPatient(patKey) {
    var query = breeze.EntityQuery
            .from("Patients")
            .where("Key", "==", patKey)
            .expand("..., ScanDates.Printouts.BMDSites, ...");

    return app.dataservice.manager.executeQuery(query);
}

BTW - this is all for a single patient, so there really isn't that much data - it's just compartmentalized quite a bit!

If anybody has any ideas, I'd be terribly grateful!

Cheers, Brad

P.S.: Obviously, I don't need a "MaxExpansionDepth = 100", but I've also tried with low values (4,5,etc)

Edit: Thanks to Dominictus, I now realize that the real problem isn't the depth of the query - the BMDSites are coming back in the response, but not materializing entities regardless of expand depth. They do materialize if I query just for them (ie BMDSites where PrintoutKey = x)... but again, this is causing ten or 15 trips to the server. I'd still love to know how to get everything at once, or just learn why these won't materialize on an expand!

Edit 2: It just occurred to me that the Printout class is the base class of a TPH inheritance hierarchy... Looking around at some of the other questions, I suspect that this is likely the source of the issue.

Upvotes: 1

Views: 655

Answers (2)

bparcels
bparcels

Reputation: 31

Turns out it had nothing to do with inheritance, or the depth of the expand... In creating a simplified model, I of course found that it worked just fine. Adding back in the features that I thought were irrelevant, I eventually broke it, and replicated my issue by adding in some [NotMapped] properties that were providing some easy access to the list of BMDSites. For example, in a class derived from Printout:

    [NotMapped]
    public BMDSite _Ud = null;

    [NotMapped]
    public BMDSite Ud
    {
        get
        {
            if (_Ud == null)
            {
                _Ud = BMDSites.Find(b => b.Region == Region.Forearm_UD);
            }
            return _Ud;
        }
    }

Upon adding this back in, once again, my list of BMDSites were not populating. Turns out that the JSON.net classes that Breeze uses don't look at [NotMapped] (which makes sense, as it is serialization, not DB mapping)... By adding a reference to JSON.net in my EF model, and adding it's equivilent tag - ie: [NotMapped, JsonIgnore], it doesn't look at the properties, and everything works just fine.

Bottom line (for those that skim)... code above causes issues, code below works fine:

    [NotMapped, JsonIgnore]
    public BMDSite _Ud = null;

    [NotMapped, JsonIgnore]
    public BMDSite Ud
    {
        get
        {
            if (_Ud == null)
            {
                _Ud = BMDSites.Find(b => b.Region == Region.Forearm_UD);
            }
            return _Ud;
        }
    }

Cheers, Brad

Upvotes: 1

Dominictus
Dominictus

Reputation: 721

If you use some other queries to Patients action, I suggest you copy Patients method, name it something like PatientsFull and in there do .Include instead of clientside expand. Sometimes expands don't work as expected. (If this is the only query to Patients then just change that method)

For some different ideas you would have to write down any possible errors that pop into console.

Upvotes: 0

Related Questions