2

在我的项目中,我使用 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; }
        }

两者都存在于同一个名称空间中,并且存在冲突。

4

1 回答 1

0

您可以删除自动生成的类并创建一个部分类来扩展 AccountModel UserProfile 类。

创建一个具有相同名称和相同命名空间的部分类:

public partial class UserProfile
{
    public UserProfile()
    {
        this.Predictions = new HashSet<Prediction>();
    }        

    public virtual ICollection<Prediction> Predictions { get; set; }
}

通过这样做,您就拥有Predictions了成员资格UserProfile类的属性。

于 2013-07-25T05:43:55.500 回答