1
votes

At my company the DBA updates our SQL Server tables to add columns, etc and when pushing these changes to prod. In my scenario we have an existing AspNetUsers table and other Identity-related tables. This existing AspNetUsers table has additional columns added (FirstName, LastName, Joined date) and the id column was changed to an 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. 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.

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? I've added the new properties to the IdentityModel.cs inside of ApplicationUser : Identity User. I've also added these fields to my AccountController's Register method and the AccountBindingModel's RegisterBindingModel class. 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.

2
There are 4 kinds of EF workflows: code-first, database-first, model-first and code-first from existing db. You don't use code-first and there is already an existing database so you are surely using database-first. But looks like you type/write all your classes by hand? It looks like what you do when using code-first.Hopeless

2 Answers

0
votes

Well, let's see:

At my company the DBA updates our SQL Server tables to add columns

As far as I understand about IT positions, an DBA should not do that. 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. EDMX has been discontinued in 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.

0
votes

You can try to use Fluent API to map your entities to database tables. fluent api