0

I have built my project using DbContext. I have created and populated database tables using code-first migration. Lately I have realized that I will need to implement Identity framework into my project. DbContext of course didn't create identity tables in DB so I was wondering what would be a best way to "replace" DbContext by IdentityDbContext so I can run 'add-migration' and update DB. This is my DbContext class which I'm using all along my project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data.Entity;
using Milos_MovieStore.Models;
using Microsoft.AspNet.Identity.EntityFramework;

namespace Milos_MovieStore.DAL
{
    public class DBContext_MovieStore : DbContext
    {
        public DbSet<Customer> Customers { get; set; }
        public DbSet<MembershipType> MembershipTypes { get; set; }
        public DbSet<Movie> Movies { get; set; }
        public DbSet<Genre> Genres { get; set; }

    }
}

... when I changed base class to:

public class DBContext_MovieStore : IdentityDbContext<ApplicationUser>
{
    public DbSet<Customer> Customers { get; set; }
    public DbSet<MembershipType> MembershipTypes { get; set; }
    public DbSet<Movie> Movies { get; set; }
    public DbSet<Genre> Genres { get; set; }

}

... it simply didn't work (EF exceptions etc.) not to mention VS2017 crashed every time I tried to add new migration. The question is what would be proper way to implement Identity into project.

cembo
  • 1,039
  • 2
  • 9
  • 18
  • There are several steps described [here](https://stackoverflow.com/questions/31960433/adding-asp-net-mvc5-identity-authentication-to-an-existing-project). Did you update the identity stuff to use DBContext_MovieStore instead of IdentityDbContext? Show one of the errors as a starting point. – Steve Greene Nov 30 '17 at 15:29
  • @Steve Greene ... Thanks. I have to mention that I am a learner, familiar with basic concept of MVC and API. I understand dbcontext and so far I have used migrations as well. So I have modified my code according to your link. I have done all steps up to web.config configuration part. So: 1 - Rebuilt - OK, 2 - when I started project ajax (dataTable) had problem but that's obviously not relevant exception. 3 - when I tried to 'add-migration Test' my VS2017 stopped working. – cembo Dec 01 '17 at 05:20
  • @Steve Greene ... here are exceptions: Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll Exception thrown: 'System.Globalization.CultureNotFoundException' in mscorlib.dll Exception thrown: 'System.Security.SecurityException' in mscorlib.dll Exception thrown: 'System.Security.SecurityException' in System.dll Exception thrown: 'System.Web.HttpException' in System.Web.dll Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll Exception thrown: 'System.Data.SqlServerCe.SqlCeException' in System.Data.SqlServerCe.dll – cembo Dec 01 '17 at 05:21
  • and here: Exception thrown: 'System.Data.SqlServerCe.SqlCeException' in mscorlib.dll – cembo Dec 01 '17 at 05:21

0 Answers0