Search code examples
angularjsasp.net-web-apiodatabreeze

Breezejs, OData can't see navigation property entity in client for many to many relationship


I'm working on many to many relationship for BreezeJS/WebAPI/OData like this: enter image description here

Metadata: enter image description here and get data with dataContext.Users.Include("Customers") is fine: enter image description here but why in result user object doesn't have customers navigation property: enter image description here

I read this article but no luck still can't use user.customers()

I'm totally stuck, please help me.

Thanks in advance.


Solution

  • EntityFramework knows about the UserCustomers table, even though it is not exposed as an entity. But Breeze only knows what is in the metadata, and EF will not generate Breeze metadata for UserCustomers unless it is exposed as an entity. (Often this is what you want anyway, because it allows you to add additional data to the relationship table, such as the date that the UserCustomer relationship was added).

    The many-to-many mapping table, UserCustomers, must be exposed as an entity. Then your metadata will include that entity, and your Customer entity will have a UserCustomers collection, and your User entity will have a UserCustomers collection.

    On the client, if you want to create a new relationship between a User and Customer, you can add a new UserCustomer entity to related them.