我正在使用带有默认 aspnet_Membership 架构的 EF5。
我有一个自定义 User 对象,其外键引用 aspnet_Membership 表。
User 对象中的外键称为“AspnetID”
我需要将这种一对一的关系与流利的 API 映射,但我没有运气
对象如下所示:
public class aspnet_Membership
{
[Key]
public Guid UserId { get; set; }
public string Email { get; set; }
public DateTime CreateDate { get; set; }
public aspnet_Users aspnet_User { get; set; }
public User User { get; set; }
}
public class User
{
public int UserID { get; set; }
[MaxLength(50)]
public string FirstName { get; set; }
[MaxLength(50)]
public string LastName { get; set; }
public Guid AspnetID { get; set; } //This is the foreign key referencing aspnet_Membership
public virtual aspnet_Membership Aspnet_Membership { get; set; }
}
我试过这个:
modelBuilder.Entity<User>().HasRequired(u => u.Aspnet_Membership).WithOptional(u => u.User);
但我知道我需要以某种方式映射外键名称......有什么想法吗?