在我的项目中,我使用 MVC4 和一些使用 Entity 作为 orm 的外部数据库。
我决定使用 MVC 提供的成员资格,所以我只是将默认更改ConnectionString
为指向我的外部数据库。
然后,当我第一次启动该应用程序时,添加了一些表格,到目前为止一切都很好。现在,问题是,当我将新创建的 userProfile 表映射到我的 dataContext 模型中时,我遇到了冲突,因为该表已经存在于 accountModel 中。
帐户模型和我新生成的模型在同一个命名空间中,我不想更改,那我该怎么办?
这是 ADO 实体模型使用视图添加表方法生成的类:
public partial class UserProfile
{
public UserProfile()
{
this.Predictions = new HashSet<Prediction>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public virtual ICollection<Prediction> Predictions { get; set; }
}
从会员这里
[Table("UserProfile")]
public partial class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
两者都存在于同一个名称空间中,并且存在冲突。