[英]Implementing asp.net Identity into already existing database with entity framework
I am trying to update an older website. 我正在尝试更新旧网站。 It already has an existing database with a user and a role table, with existing data in it.
它已经有一个包含用户和角色表的现有数据库,其中包含现有数据。
I need to create a new web-api and a new web project and integrate ASP.NET Identity into the already existing database. 我需要创建一个新的web-api和一个新的Web项目,并将ASP.NET Identity集成到现有的数据库中。
I have currently setup my solution to breakup the projects as follows: 我目前正在设置解决方案以解决项目,如下所示:
My aim is to implement the Identity in the services layer so that both my WebAPI and MVC site can utilize the same identity mechanism. 我的目标是在服务层实现Identity,以便我的WebAPI和MVC站点都可以使用相同的身份机制。
I am fairly overwhelmed at the moment, I have read many tutorials and articles over the last day or two and have ended up with the options of either re-implementing the IUserStore
and IRoleStore
. 我现在相当不知所措,我在过去一两天内阅读了许多教程和文章,并最终选择了重新实现
IUserStore
和IRoleStore
。 And also with mapping the different entities in the OnModelCreatingMethod
. 并且还可以映射
OnModelCreatingMethod
的不同实体。
I cant seem to find a tutorial which is aimed at what I want to do. 我似乎找不到针对我想做的教程。 My database is to different to simply remap the names of columns, And I dont want to re-implement the entire Identity Stores as there are only a few conflicting fields.
我的数据库不同于简单地重新映射列的名称,而且我不想重新实现整个Identity Stores,因为只有少数冲突的字段。 Most tuts I have found are related to using mysql instead of EF.
我发现的大部分内容都与使用mysql而不是EF有关。 I still want to make use Entity Framework.
我还是想使用Entity Framework。
Issues I have: 我遇到的问题:
Int
pk , not GUID
Int
pk,而不是GUID
So basically my question is, In what direction do I need to go in order to overcome the above mentioned issues. 所以基本上我的问题是,为了克服上述问题,我需要朝哪个方向前进。 Can I get away with changing the Database mapping?
我可以通过更改数据库映射来逃脱吗? Or do I need to go as far as re implementing the User and Role Stores?
或者我是否需要重新实现用户和角色存储?
What I had initially planned was to re-implement the User and Role Stores using entity framework, And i could then make use if the DB first model classes and map the actual DB structure and fields to my ApplicationUser Fields. 我最初计划的是使用实体框架重新实现用户和角色存储,然后我可以使用,如果数据库首先建模类并将实际的数据库结构和字段映射到我的ApplicationUser字段。 But this is where I thought I might be diving into cold waters, and i'm generally not a fan of reinventing the wheel if not necessary.
但这就是我认为我可能潜入寒冷水域的地方,如果没有必要,我通常不会重新发明轮子。
-The first thing you should do if you haven't already is to BACK-UP your current database! - 如果您还没有备份当前数据库,首先应该做的事情!
You could use code first to update an existing database. 您可以首先使用代码来更新现有数据库。
I found this walkthrough and it seemed close to the route you're on, and I'm hoping it will help solve your problem, begin at "Migrating to Visual Studio 2013". 我找到了这个演练,它似乎接近你所在的路线,我希望它有助于解决你的问题,从“迁移到Visual Studio 2013”开始。 http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity
http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity
This would create a few new tables, but not necessarily a new database. 这将创建一些新表,但不一定是新数据库。
Download Nuget packages: Microsoft.AspNet.Identity.EntityFramework, Microsoft.AspNet.Identity.Owin, Microsoft.Owin.Host.SystemWeb 下载Nuget软件包:Microsoft.AspNet.Identity.EntityFramework,Microsoft.AspNet.Identity.Owin,Microsoft.Owin.Host.SystemWeb
Enable-migrations and run a script such as this: https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/SQLMembership-Identity-OWIN/Migrations.sql 启用迁移并运行如下脚本: https : //aspnet.codeplex.com/SourceControl/latest#Samples/Identity/SQLMembership-Identity-OWIN/Migrations.sql
Or you could try using a reverse POCO generator found in visual studio extensions. 或者您可以尝试使用Visual Studio扩展中的反向POCO生成器。
(My 1st attempt at writing an answer here. Tried to clarify.) (我第一次尝试在这里写答案。试图澄清。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.