New Posts New Posts RSS Feed: Many-to-Many Error
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Many-to-Many Error

 Post Reply Post Reply
Author
SirSmackalot View Drop Down
Newbie
Newbie


Joined: 22-Oct-2012
Posts: 4
Post Options Post Options   Quote SirSmackalot Quote  Post ReplyReply Direct Link To This Post Topic: Many-to-Many Error
    Posted: 02-Nov-2012 at 8:51am
Hi there,

i am defining some of my models atm using EF5 Code First. I have these three sample classes with a many-to-many relationship:

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 there is a many-to-many relationship between teams and users. I am trying to get this to work for hours.
I always get an JS Exception with the error message "bad nav properties" in VS 2012.
At first i thought it was the ICollections Teams/Users in Users/Teams-Class but it wasnt. The problem seems to be the two calls 1) and 2). I f i remove either one of them it works. Renaming one and keeping both fields active still throws the error.
Maybe anyone has an idea what is going on.

Many thanks

Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 02-Nov-2012 at 10:57am
Breeze doesn't yet support many-to-many relations where the mapping table is hidden. The problem is that we depend on a "foreignKey"concept to keep track of relationships and this is not available for many-to-many relations. 

What does work now is to change your many-to-many relationship into two 1-to-many relations with a linking object. Basically, just expose the mapping table as another entity type. For example:

Team -- TeamUser  (1-to-many)
User -- TeamUser  (1-to-many)

We do plan to support Entity Framework's official many-to-many relationship in a later release but we need to prioritize this. So please add and vote for this feature request using the feedback mechanism on the web site (small icon on the right side of any Breeze website page labeled "Feedback"). This helps us decide which features to focus on next.



Edited by ting - 02-Nov-2012 at 11:24am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down