EntityFramework创建额外的列

时间:2012-08-29 08:15:12

标签: entity-framework

我有以下课程:

public partial class User
{
    [Key]
    public int UserId { get; set; }
    public string Username { get; set; }
    [ScriptIgnore]
    public virtual ICollection<Subscription> Followers { get; set; }
    [ScriptIgnore]
    public virtual ICollection<Subscription> Following { get; set; }
}

public partial class Subscription
{
    [Key]
    public int SubscriptionId { get; set; }
    public virtual User Follower { get; set; }
    public virtual User Followed { get; set; }
    public int status { get; set; }
}

用户表生成正常,但订阅表如下所示:

Subscriptions( SubscriptionId, status, Follower_UserId, Followed_UserId, 
User_UserId, User_UserId1 )

这两个最后一列不是必需的,它们实际上是NULL值

1 个答案:

答案 0 :(得分:3)

尝试使用它:

public partial class Subscription
{
    [Key]
    public int SubscriptionId { get; set; }
    [InverseProperty("Followers")]
    public virtual User Follower { get; set; }
    [InverseProperty("Following")]
    public virtual User Followed { get; set; }
    public int status { get; set; }
}