微风中的多对多关系 [英] Many-to-many relations in Breeze

查看:128
本文介绍了微风中的多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EF5 Code First定义我的一些模型atm。我有这些
三个样本类与多对多关系:

  public class Team 
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Team_Id {get;组; }
[MaxLength(150)]
public string TeamName {get;组; }

public virtual ICollection< User>用户{get;组; }
[public virtual ICollection< Role>角色{get;组; } // 1

[Timestamp]
public byte [] TimeStamp {get;组;


public class User
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int User_Id {get;组; }
[MaxLength(150)]
public string LoginName {get;组; }
[MaxLength(150)]
public string Nachname {get;组; }
[MaxLength(150)]
public string Vorname {get;组; }

public virtual ICollection< Team>团队{get;组; }
public virtual ICollection< Role>角色{get;组; } // 2

[Timestamp]
public byte [] TimeStamp {get;组;


public class Role
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Role_Id {get;组; }
[MaxLength(50)]
public string RoleName {get;组; }

[Timestamp]
public byte [] TimeStamp {get;组; }
}

正如你所看到的那样,团队之间有多对多的关系和
个用户。我试图让这个工作几个小时。我总是得到一个JS
异常,并在VS 2012中显示错误消息bad nav properties。在
首先我以为是
用户/团队类中的ICollections团队/用户wasnt。问题似乎是两个电话
1)和2)。我要删除任何一个它的工作。重命名一个和
保持两个字段的活动仍然会抛出错误。也许任何人都有
一个想法发生了什么。



非常感谢


这个问题由SirSmackalot发布在我们的IdeaBlade论坛上。我正在转发这个问题,因为我认为这对Breeze Stack Overflow社区是有用的。

解决方案

Breeze doesn' t支持映射表隐藏的多对多关系。问题是,微风依赖于一个外键概念来跟踪关系,而这不适用于在实体框架中无负载定义的多对多关系。



有什么工作是将多对多关系改为与连接实体的两对一对多关系。基本上,只是将映射表暴露为另一个实体类型。例如:



团队 - TeamUser(1对多)



用户 - TeamUser(1 to-many)



我们计划在稍后的版本中支持实体框架的官方多对多关系,但是我们需要确定这一点。所以,请使用网站上的反馈机制来添加/投票使用此功能请求( https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions/filters/top )。这有助于我们确定下一步要关注哪些功能。


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

This question was posted by SirSmackalot on our IdeaBlade forums. I am reposting the question and answer here since I think it will be useful to the Breeze Stack Overflow community.

解决方案

Breeze doesn't yet support many-to-many relations where the mapping table is hidden. The problem is that Breeze depends on a "foreign key" concept to keep track of relationships, and this is not available for many-to-many relations defined with no payload in the Entity Framework.

What does work is to change the many-to-many relationship into two 1-to-many relations with a linking entity. 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/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.

这篇关于微风中的多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆