2

I have VS 2013, Update 4, if it's relevant.

ASP Identity supports only code-first, but I have an existing database. So, I'm trying to install T4 template for EF db first with ASP Identity, following instructions from https://github.com/cbfrank/AspNet.Identity.EntityFramework

Installed EF Power Tools successfully. Next step was to install T4 template from NuGet:https://www.nuget.org/packages/cb.AspNet.Identity.EntityFramework.T4/

But when trying to install from NuGet Console, I get error:

"Install-Package : Unable to find package cb.AspNet.Identity.EntityFramework.T4"

I haven't found any instructions on how to install the package manually.

Please advise, how to install this T4 template or suggest other solution - how to use ASP Identity with existing database.

Thank you.


Update:

I've followed instructions from Daniel Eagle's blog (see my comment for url, system doesn't allow to paste hyperlink) However, when I tried to run application and register a new user, exception appeared:

"The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database

Exception Details: System.InvalidOperationException: The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database.

Source Error:

Line 153: { Line 154: var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; Line 155: var result = await UserManager.CreateAsync(user, model.Password); Line 156: if (result.Succeeded) Line 157: {

Source File: c:\Users\Valeriya\Documents\Visual Studio 2013\Projects\Bulk_mailer_6\Bulk_mailer_6\Controllers\AccountController.cs Line: 155 "

Valeriya
  • 1,067
  • 2
  • 16
  • 31
  • Have a look at following post http://stackoverflow.com/questions/20668328/using-asp-net-identity-database-first-approch – Simranjeet Singh Dec 08 '14 at 06:12
  • Thank you, Simranjeet, I've checked suggested post and I've followed the instruction provided by Daniel Eagle in his blog: http://danieleagle.com/blog/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template However, when I tried to run the application and register a new user, exception popped up. – Valeriya Dec 08 '14 at 14:01
  • The error usually occurs when the database is not in sync with the classes defined in your applications. The solutions is to use migrations and bring the database in sync with the defined classes and properties. Hope this helps!. – Simranjeet Singh Dec 10 '14 at 10:11
  • Right, I see now, thanks. I've already given up and applying code first, though. I think, it will take less time to re-insert my sample data to db, then troubleshoot db first. – Valeriya Dec 10 '14 at 15:35

1 Answers1

0

The error you have indicates that your entities changed after the database was created by Entity Framework Code First. You can manually delete the database or use Code First Migrations as exception suggests.

Sergey Kolodiy
  • 5,829
  • 1
  • 36
  • 58
  • Right. My problem is, database was never created by code first. I was trying to trick EF and point it to an existing database, following instructions on http://danieleagle.com/blog/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template but run into that exception. I tried to enable Code First Migrations, it complained that I have more than once context within my assembly. So, I enabled it for both contexts. I still see the same exception when I run it. Maybe I should just go for Code first, after all... – Valeriya Dec 09 '14 at 08:39
  • @Lera So you are using Database First, right? Then you can regenerate your `.edmx` schema from the database and check if it solves the issue. By the way, why do you have multiple `DbContext`s? Do you have more than one database? – Sergey Kolodiy Dec 09 '14 at 08:54
  • Yes, I tried to use Database First with ASP Identity. By didn't succeed. Yes, that's what I did - created .edmx from existing database (following the instructions of the mentioned blog). No, I have only 1 database, but I think because I'm manually replacing the target database, EF still points to the initial default identity database somewhere in there. I've abandoned this idea though and developing with code first... – Valeriya Dec 10 '14 at 04:25