简体   繁体   English

ASP.NET MVC-将Identity与现有的经过修改的AspNetUsers表一起使用

[英]ASP.NET MVC - Using Identity with existing, modified AspNetUsers table

At my company the DBA updates our SQL Server tables to add columns, etc and when pushing these changes to prod. 在我公司,DBA更新我们的SQL Server表以添加列等,并将这些更改推送到产品中。 In my scenario we have an existing AspNetUsers table and other Identity-related tables. 在我的方案中,我们有一个现有的AspNetUsers表和其他与Identity相关的表。 This existing AspNetUsers table has additional columns added (FirstName, LastName, Joined date) and the id column was changed to an int. 此现有的AspNetUsers表添加了其他列(名字,姓氏,加入日期),并且id列已更改为int。

I'm writing a new MVC Web Api (VS 2013) on top of this existing database and I started with the default Web Api template that uses Identity which I really like. 我在此现有数据库之上编写了一个新的MVC Web Api(VS 2013),并从使用我真正喜欢的Identity的默认Web Api模板开始。 I can't use Code-First since the tables already exist and already have these additional fields. 我不能使用代码优先,因为这些表已经存在并且已经具有这些其他字段。 I will not and cannot have my code update the DB through Nuget, and I'm not responsible for creating DB scripts either. 我不会,也不会让我的代码通过Nuget更新数据库,我也不负责创建数据库脚本。

My question is: How can I have my code work with an existing AspNetUsers table that has additional fields that I'll need to capture when registering the user? 我的问题是:如何让我的代码与现有的AspNetUsers表一起使用,该表具有注册用户时需要捕获的其他字段? I've added the new properties to the IdentityModel.cs inside of ApplicationUser : Identity User. 我已将新属性添加到ApplicationUser中的IdentityModel.cs中:Identity User。 I've also added these fields to my AccountController's Register method and the AccountBindingModel's RegisterBindingModel class. 我还将这些字段添加到了AccountController的Register方法和AccountBindingModel的RegisterBindingModel类中。 The error I'm getting when registering the user is "Mapping and metadata information could not be found for EntityType Phoenix.WebAPI.Models.ApplicationUser" and I don't know how to approach this since I'm not allowed to touch the DB and don't want to use Code-First. 注册用户时出现的错误是“找不到EntityType Phoenix.WebAPI.Models.ApplicationUser的映射和元数​​据信息”,并且由于无法触摸数据库,我不知道该如何处理并且不想使用Code-First。

Well, let's see: 好吧,走着瞧:

At my company the DBA updates our SQL Server tables to add columns 在我公司,DBA更新了我们的SQL Server表以添加列

As far as I understand about IT positions, an DBA should not do that. 据我了解的IT职位,DBA不应该这样做。 Database modelling is a job for an Analyst. 数据库建模是分析师的工作。

I can't use Code-First since the tables already exist and already have these additional fields 我不能使用代码优先,因为这些表已经存在并且已经具有这些其他字段

That is not right. 那是不对的。 You can use Code-First in a existing database, it also works way better than EDMX. 您可以在现有数据库中使用Code-First,它的工作方式也比EDMX好。 EDMX has been discontinued in EF7. EDMX已在EF7中停产。

However, if you really don't want to use Code-First, take a look at this library https://github.com/kriasoft/AspNet.Identity it might be helpful. 但是,如果您真的不想使用Code-First,请查看此库https://github.com/kriasoft/AspNet.Identity可能会有所帮助。

You can try to use Fluent API to map your entities to database tables. 您可以尝试使用Fluent API将您的实体映射到数据库表。 fluent api 流利的api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ASP.Net Identity EntityFramwork到ID列设置为UniqueIdentifier的现有AspNetUsers表 - Using ASP.Net Identity EntityFramwork to Existing AspNetUsers table with ID Column set to UniqueIdentifier dbo.AspNetUsers 表上的 ASP.NET MVC 5 核心标识 CompanyID 外键 - ASP.NET MVC 5 Core Identity CompanyID foreign key on dbo.AspNetUsers table 是否将用户设置存储在ASP.NET Core身份AspNetUsers表中 - Store User Settings in ASP.NET Core Identity AspNetUsers Table or Not ASP.NET Identity 从 AspNetUsers 表中删除列 - ASP.NET Identity remove column from AspNetUsers table ASP.NET 核心 AspNetUsers 上的身份 - Identity on ASP.NET Core AspNetUsers ASP.NET MVC标识与现有用户表 - ASP.NET MVC Identity with existing user table 如何获取ASP.Net MVC 5中AspNetUsers表中的ApplicationUser数量? - How to get the Number of ApplicationUser in the AspNetUsers Table in ASP.Net MVC 5? Asp.net核心 - 没有这样的表:AspNetUsers - Asp.net core - no such table: AspNetUsers 在MVC中将ASP.NET Identity 2.2.1与我自己的表一起使用 - Using ASP.NET Identity 2.2.1 with my own table in MVC 如何有条件地将 map 多个模型添加到 ASP.NET 核心标识中的一张表(AspNetUsers)? - How to conditionally map multiple models to one table (AspNetUsers) in ASP.NET Core Identity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM