Using Asp.net 4.5 and VS 2013, I would like to know how to integrate Asp.Net Identity Tables with an existing database.
使用Asp.net 4.5和VS 2013,我想知道如何将Asp.Net Identity Tables与现有数据库集成。
So basically I would like to have db tables for Identity and my own tables in the same db.
所以基本上我想在同一个数据库中拥有Identity表和我自己的表的数据库表。
I know Asp.Net Identity use Code First approach but I would like to use DB first approach for my existing db. I am little confuse.
我知道Asp.Net Identity使用Code First方法,但我想对我现有的数据库使用DB第一种方法。我有点困惑。
How would you handle this?
你会怎么处理这个?
Does it make sense keep Asp.Net Identity Tables in a different database that my own Tables?
将Asp.Net Identity Tables保存在与我自己的表不同的数据库中是否有意义?
2 个解决方案
#1
2
I think that depends preety much on what you want to achieve.
我认为这在很大程度上取决于你想要实现的目标。
Is it a single asp.Net application that you are developing or a set of different apps that would use the same database?
它是您正在开发的单个asp.Net应用程序还是一组使用相同数据库的不同应用程序?
Here there is an answer I pretty much agree with. Separate schema and one database for one app/database. Two databases kind of beat the point of separation but three databases might be a better solution if the authorization rules remain the same.
这里有一个我非常同意的答案。为一个应用程序/数据库分隔模式和一个数据库。两种数据库超越了分离点,但如果授权规则保持不变,则三个数据库可能是更好的解决方案。
As for the DB first approach there is a pretty good article (and code) here.
至于DB第一种方法,这里有一篇非常好的文章(和代码)。
#2
0
Edit your identitymodel to override model creation and point to your existing tables you have set-up
编辑您的identitymodel以覆盖模型创建并指向您已设置的现有表
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("Users");
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
}
#1
2
I think that depends preety much on what you want to achieve.
我认为这在很大程度上取决于你想要实现的目标。
Is it a single asp.Net application that you are developing or a set of different apps that would use the same database?
它是您正在开发的单个asp.Net应用程序还是一组使用相同数据库的不同应用程序?
Here there is an answer I pretty much agree with. Separate schema and one database for one app/database. Two databases kind of beat the point of separation but three databases might be a better solution if the authorization rules remain the same.
这里有一个我非常同意的答案。为一个应用程序/数据库分隔模式和一个数据库。两种数据库超越了分离点,但如果授权规则保持不变,则三个数据库可能是更好的解决方案。
As for the DB first approach there is a pretty good article (and code) here.
至于DB第一种方法,这里有一篇非常好的文章(和代码)。
#2
0
Edit your identitymodel to override model creation and point to your existing tables you have set-up
编辑您的identitymodel以覆盖模型创建并指向您已设置的现有表
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("Users");
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
}