C# 首先使用EF代码更改自动生成的N:M表上的列名称

C# 首先使用EF代码更改自动生成的N:M表上的列名称,c#,entity-framework,entity-framework-4,C#,Entity Framework,Entity Framework 4,我正在使用最新版本的实体框架和VS2010,使用C#开发一个类库。我有这门课: public class User { public int UserId { get; set; } public String Name { get; set; } public int Age { get; set; } public String City { get; set; } public String Country { get; set; } pub

我正在使用最新版本的实体框架和VS2010,使用C#开发一个类库。我有这门课:

public class User
{
    public int UserId { get; set; }
    public String Name { get; set; }
    public int Age { get; set; }
    public String City { get; set; }
    public String Country { get; set; }
    public String Email { get; set; }
    public String InterestIn { get; set; }

    public List<User> Friends { get; set; }
    public List<User> FromWhomIsFriend { get; set; }
    public List<Activity> WantsToDo { get; set; }
    public List<Message> MessagesSent { get; set; }
    public List<Message> MessagesReceived { get; set; }
}
公共类用户
{
public int UserId{get;set;}
公共字符串名称{get;set;}
公共整数{get;set;}
公共字符串City{get;set;}
公共字符串国家{get;set;}
公共字符串电子邮件{get;set;}
公共字符串InterestIn{get;set;}
公共列表朋友{get;set;}
来自whomisfriend{get;set;}的公共列表
公共列表WantsToDo{get;set;}
公共列表消息sent{get;set;}
收到的公共列表消息{get;set;}
}
EF在SQLEXPRESS上生成了以下两个表:

我有三个问题:

  • 如何将表
    dbo.UserUsers
    重命名为
    dbo.UserFriends
  • 如何将其两列重命名为
    UserId
    FriendId
  • 如何将
    UserId
    FriendId
    列设置为
    dbo.UserFriends
    表的主键

  • 注意:这是我第一次首先使用EF代码。

    最简单的选择是在您的模型中创建此表。如果EF检测到这样的表,它将不会创建另一个表。 要自定义列名,请查看此处: