在 sql 服务器中创建了两个用户配置文件 table
two user profile table created in sql server
我的Accountmodels.csclass是这样的---
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
public class RegisterExternalLoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
public string ExternalLoginData { get; set; }
}
我的用户资料class是这样的---
public class UserProfile
{
public UserProfile()
{
this.Posts = new HashSet<Post>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public string AvatarExt { get; set; }
public virtual ICollection<Post> Posts { get; set; }
最后我的 dbContext class 是----
public class WallEntities : DbContext
{
public WallEntities()
: base("name=WallEntities")
{
}
public DbSet<Post> Posts { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }
我在连接中同时使用 WallEntities 和 DefaultConnection 作为名称 string.I 我正在使用简单成员资格,所以我有一个 InitializeSimpleMembershipAttribute.cs File.Its 看起来像这样---
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}.
我的问题是它在 Sql 中创建两个 table server.One 是 UserProfile,另一个是 UserProfiles table.I 只想创建1 table 即 UserProfile table with UserId,UserName 和 AvatarExt Property.After 注册,它应该存储所有信息。
我想回答我的问题,它可能对某人有用---
只是这里的问题不是使用其中的两个 DbContext.Instead,对于代码第一种方法,一个 dbContext 就足够了。
那么,DbContext应该是这样的----
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<Post> Posts { get; set; }
it should not be here
// public DbSet<UserProfile> UserProfiles { get; set; }
}
并删除 WallEntities DbContext。并从 UserContext 中删除 USerFrofile,正如我注释掉的那样,并以相同的方式更改所有相应的代码。
我的Accountmodels.csclass是这样的---
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
public class RegisterExternalLoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
public string ExternalLoginData { get; set; }
}
我的用户资料class是这样的---
public class UserProfile
{
public UserProfile()
{
this.Posts = new HashSet<Post>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public string AvatarExt { get; set; }
public virtual ICollection<Post> Posts { get; set; }
最后我的 dbContext class 是----
public class WallEntities : DbContext
{
public WallEntities()
: base("name=WallEntities")
{
}
public DbSet<Post> Posts { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }
我在连接中同时使用 WallEntities 和 DefaultConnection 作为名称 string.I 我正在使用简单成员资格,所以我有一个 InitializeSimpleMembershipAttribute.cs File.Its 看起来像这样---
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}.
我的问题是它在 Sql 中创建两个 table server.One 是 UserProfile,另一个是 UserProfiles table.I 只想创建1 table 即 UserProfile table with UserId,UserName 和 AvatarExt Property.After 注册,它应该存储所有信息。
我想回答我的问题,它可能对某人有用---
只是这里的问题不是使用其中的两个 DbContext.Instead,对于代码第一种方法,一个 dbContext 就足够了。
那么,DbContext应该是这样的----
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<Post> Posts { get; set; }
it should not be here
// public DbSet<UserProfile> UserProfiles { get; set; }
}
并删除 WallEntities DbContext。并从 UserContext 中删除 USerFrofile,正如我注释掉的那样,并以相同的方式更改所有相应的代码。