English 中文(简体)
如何利用《反歧视法》建立一种与多种关系。 NET 实体框架法第一版
原标题:How to create a one to many relationship using ADO.NET Entity Framework Code First?

我正在与一个问题和我所看到的没有任何预谋解决办法的工作作斗争。

基本上,我有两个班子:

public class Role
{
    [Key]
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public class ActionType
{
    public int ID { get; set;}
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual ICollection<Role> AllowedRoles { get; set; }

    public ActionType()
    {
        this.AllowedRoles = new List<Role>();
    }  
}

我要请欧洲论坛在非洲开发银行内设立一个联系表,利用该表来提及这种关系。 有些代码首先为我的<代码>Role建立一个表格,其中增加了一个栏目。 当然,在增加<条码>时没有用处。 作用添加到<代码>中。 类型

关于我应如何解决这一问题的想法? 这里的意思是,“作用”一词指的是“行动”一词,因为这并不有用。

谢谢!

最佳回答

你真的想做些什么? 现在,你可以增加<条码>。 作用至单一<代码> 类型,但单项<编码>不能添加到多个<代码>。 类型。 你们是否也希望这样做?

在这种情况下,你不从事一对一的协会,而是从事许多对手。 只有许多对手关系使用禁令表(协会)。 “一对一”关系的确意味着依赖实体(许多方面)拥有科索沃信托公司的主要实体。 最简单的方法也是界定航行财产在发挥作用:

public class Role
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual ICollection<ActionType> ActionTypes { get; set; } 
}

public class ActionType
{
    public int ID { get; set;}
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual ICollection<Role> AllowedRoles { get; set; } 
}

如果你不想让航行财产发挥作用,那么你必须使用流星号描述关系。

public class Context : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<ActionType>()
                    .HasMany(a => a.AllowedRoles)
                    .WithMany();
    }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签