3

Entity property 'Devices' goes missing from my account entity between the server's JSON response and QuerySucceeded callback

When I check my JSON I can see the array of devices on my returned account object. When I put a breakpoint in my QuerySucceeded method the data.response Account object has no 'Devices' property.

Some extra information:

  • I made a many to many relationship in EF Code First by making a collection of Devices on my Account model and a collection of Accounts on my Device model. These are also mapped, etc
  • I am expanding devices from the account entity
  • Even if I don't do an 'expand' there is still no 'devices' property on the object.
  • There is another collection on the Account entity called ReportConfigurations. This entity shows up as a property in the response fine (this is a 1 to many).
  • This is my first time modifying the database with CodeFirst. I intially had a database and used a power tool to convert it into Code First. Because of this I could be missing something that is causing it to not be mapped properly but nothing sticks out to me....

Here is the relevant part in AccountMap.cs:

this.HasMany(t => t.Devices)
                .WithMany(t => t.Accounts)
                .Map(m =>
                    {
                        m.ToTable("DeviceAccounts");
                        m.MapLeftKey("Account_Id");
                        m.MapRightKey("Device_Id");
                    });

Relevant parts from Account.cs:

public Account()
        {
            this.Devices = new List<Device>();
        }
public virtual ICollection<Device> Devices { get; set; }

and finally my query:

var query = entityQuery.from('Accounts')
                .where('id', 'eq', id)
                .expand('devices')
                .orderBy('givenName, familyName');

enter image description here

Any ideas for what could be causing this?

2
  • I am having the same problem. I loaded the breeze.debug.js version 1.4.1 so that I could see where I was losing the data. In the function executeQueryCore on the return there is an executeQuery function being called. On line 13226 of the debug file the nodes variable has the navigation property listed with its values. After nodes.map is called the results variable does not have the navigation property at all. One other note on my issue: I have two navigation properties one is working and the other is not. Both are defined the same way. Commented Sep 25, 2013 at 20:13
  • I just went through the same Code First process adding a basic String property to the Account model and it worked. This makes me think it must be related to how I'm creating the collection of devices. Commented Sep 25, 2013 at 23:43

1 Answer 1

1

Many to many relationships aren't supported in Breeze unless you expose the join table.

Found the answer here: Many-to-many relations in Breeze

There is also an ongoing suggestion to support this in Breeze here: https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions/suggestions/3317477-many-many-relationship-for-ef

To get an observableArray of devices from an Account I have to make a for loop to go through each item in Account.DeviceAccounts and push the internal Device to an observableArray.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.