ASP.NET Identity with EF Database First MVC5
It should be possible to use the identity system with POCO and Database First, but you'll have to make a couple of tweaks:
- Update the .tt-file for POCO generation to make the entity classes
partial
. That will make it possible for you to supply additional implementation in a separate file. - Make a partial implementation of the
User
class in another file
partial User : IUser{}
That will make the User
class implement the right interface, without touching the actual generated files (editing generated files is always a bad idea).
My steps are very similar but I wanted to share.
1) Create a new MVC5 project
2) Create a new Model.edmx. Even if it's a new database and has no tables.
3) Edit web.config and replace this generated connectionstring:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-SSFInventory-20140521115734.mdf;Initial Catalog=aspnet-SSFInventory-20140521115734;Integrated Security=True" providerName="System.Data.SqlClient" />
with this connectionstring:
<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;database=SSFInventory;integrated security=true;" providerName="System.Data.SqlClient" />
Afterwards, build and run the application. Register a user and then the tables will be created.
EDIT: ASP.NET Identity with EF Database First for MVC5 CodePlex Project Template.
I wanted to use an existing database and create relationships with ApplicationUser. This is how I did it using SQL Server but the same idea would probably work with any DB.
- Create an MVC Project
- Open the DB listed under the DefaultConnection in Web.config. It will be called (aspnet-[timestamp] or something like that.)
- Script the database tables.
- Insert the scripted tables into existing database in SQL Server Management Studio.
- Customize and add relationships to ApplicationUser (if necessary).
- Create new Web Project > MVC > DB First Project > Import DB with EF ... Excluding the Identity Classes you inserted.
- In IdentityModels.cs change the ApplicationDbContext
:base("DefaltConnection")
to use your project's DbContext.
Edit: Asp.Net Identity Class Diagram