Asp.net mvc MVC4重复用户配置文件表
在我的项目中,我使用MVC4和一些使用实体作为orm的外部数据库 我决定使用MVC提供的成员资格,所以我只是更改了默认的Asp.net mvc MVC4重复用户配置文件表,asp.net-mvc,entity-framework,asp.net-mvc-4,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,在我的项目中,我使用MVC4和一些使用实体作为orm的外部数据库 我决定使用MVC提供的成员资格,所以我只是更改了默认的ConnectionString以指向我的外部数据库 然后,当我第一次启动应用程序时,添加了一些表格,到目前为止还不错。现在,问题是,当我将新创建的userProfile表映射到我的dataContext模型时,我遇到了冲突,因为accountModel中存在这个表allready 帐户模型和我新生成的模型在同一个名称空间中,我不想更改,所以我能做什么 下面是ADO实体模型使用
ConnectionString
以指向我的外部数据库
然后,当我第一次启动应用程序时,添加了一些表格,到目前为止还不错。现在,问题是,当我将新创建的userProfile表映射到我的dataContext模型时,我遇到了冲突,因为accountModel中存在这个表allready
帐户模型和我新生成的模型在同一个名称空间中,我不想更改,所以我能做什么
下面是ADO实体模型使用view add tables方法生成的类:
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; }
}
两者都存在于相同的名称空间中,并且存在冲突。您可以删除自动生成的类并创建一个分部类来扩展AccountModel UserProfile类 创建具有相同名称和相同命名空间的分部类:
public partial class UserProfile
{
public UserProfile()
{
this.Predictions = new HashSet<Prediction>();
}
public virtual ICollection<Prediction> Predictions { get; set; }
}
公共部分类UserProfile
{
公共用户配置文件()
{
this.Predictions=newhashset();
}
公共虚拟ICollection预测{get;set;}
}
通过这样做,您可以将
预测
属性放入membershipUserProfile
类中。您可以提供更多信息吗?在global.asax或名为“InitializeSimpleMembershipAttribute”的类中的筛选器文件夹下的方法中写入的连接字符串是什么,类似于此WebSecurity.InitializeDatabaseConnection(DEFAULTCONNECTION,“UserProfile”,“UserId”,“UserName”,autoCreateTables:true);我没有完全理解你,我找到了你提到的WebSecurity的方法;然后我的webconfig中的DefaultConnection看起来是这样的:问题是这个成员身份已经有了userProfile类的定义,但是假设我在我的主模型中有另一个与userProfil相关的表,所以我映射了这两个表:这个表和userProfile表,然后我们遇到了一个问题,first visual说,这个类有allrady定义,所以让它成为partial,但我不想手动更改模型,但即使我更改为partial,我们也有冗余字段等等……您是先使用实体框架代码吗?你能把数据上下文添加到你的问题中吗?不,我不是先用代码,我说的是“映射表”这个词,我用的是desinger
public partial class UserProfile
{
public UserProfile()
{
this.Predictions = new HashSet<Prediction>();
}
public virtual ICollection<Prediction> Predictions { get; set; }
}