相关疑难解决方法(0)

复合键作为外键

我在MVC 3应用程序中使用Entity framework 4.1.我有一个实体,我有主键由两列(复合键)组成.并且这在另一个实体中用作外键.如何建立关系?在普通的scnerios我们使用:

public class Category
{
    public string CategoryId { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Product> Products { get; set; }
}

public class Product
{
    public int ProductId { get; set; }
    public string Name { get; set; }
    public string CategoryId { get; set; }

    public virtual Category Category { get; set; }
} 
Run Code Online (Sandbox Code Playgroud)

但是如果类别有两列键怎么办?

c# entity-framework foreign-keys composite-key ef-code-first

80
推荐指数
2
解决办法
7万
查看次数