Many-to-Many Relationships in Breeze

I define some of my models using the EF5 Code First. I have these three classes of examples with many relationships:

public class Team { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Team_Id { get; set; } [MaxLength(150)] public string TeamName { get; set; } public virtual ICollection<User> Users { get; set; } [public virtual ICollection<Role> Roles { get; set; } // 1 [Timestamp] public byte[] TimeStamp { get; set; } } public class User { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int User_Id { get; set; } [MaxLength(150)] public string LoginName { get; set; } [MaxLength(150)] public string Nachname { get; set; } [MaxLength(150)] public string Vorname { get; set; } public virtual ICollection<Team> Teams { get; set; } public virtual ICollection<Role> Roles { get; set; } // 2 [Timestamp] public byte[] TimeStamp { get; set; } } public class Role { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Role_Id { get; set; } [MaxLength(50)] public string RoleName { get; set; } [Timestamp] public byte[] TimeStamp { get; set; } } 

As you can see, between teams and many users. I'm trying to get this to work for hours. I always get a JS Exception with the "bad nav properties" error message in VS 2012. At first I thought that these were ICollections / Users in Users / Class commands, but that was not the case. The problem seems to be in two calls 1) and 2). I delete one of them, it works. Renaming one and keeping both fields active still gives an error. Maybe someone has an idea of ​​what is going on.

Many thanks

This question has been submitted by SirSmackalot on our IdeaBlade forums. I am returning the question and answering here, as I think it will be useful for the Breeze Stack Overflow community.

+7
source share
1 answer

The breeze does not yet support many-to-many relationships where the display table is hidden. The problem is that Breeze depends on the concept of a “foreign key” to track relationships, and this is not available for many-to-many relationships defined without the payload in the Entity Framework.

What the job is to change the many-to-many relationship into two one-to-many relationships with the connecting object. Basically, just show the mapping table as another type of object. For example:

Team - TeamUser (1-to-many)

User - TeamUser (1-to-many)

We plan to maintain a formal Entity Framework many-to-many relationship in a later release, but we need to set priorities. Therefore, please add / vote for this feature request using the feedback mechanism on the website ( https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions/filters/top ). This helps us decide which features to focus on next.

+14
source

All Articles