【问题标题】:Fluent API, define a primary key as foreign keyFluent API,定义主键为外键
【发布时间】:2013-03-26 11:22:41
【问题描述】:

我有这两个模型:

//Primary AND Foreign key 1
public int UserID {get; set;}

//Primary AND Foreign key 2
public int ProductID {get; set;}

我不知道如何将这两列同时设置为主键和外键! 你能帮帮我吗?

【问题讨论】:

标签: c# entity-framework ef-code-first foreign-keys primary-key


【解决方案1】:

你可能正在寻找这个

    //Primary AND Foreign key 1
[Key]
 public int UserID {get; set;}
[ForeignKey("UserID")]
public virtual IEnumerable<UserProfile> users;

    //Primary AND Foreign key 2

public int ProductID {get; set;}
[ForeignKey("ProductID")]
public virtual IEnumerable<Product> products;

这将允许您从用户导航到产品。

如果这不是您想要的,请提供更多关于您需要的详细信息

【讨论】:

    猜你喜欢
    • 2014-05-26
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多