2

I tried the ASP.Net identity and it works fine. I then tried to get it working with an existing SQL database using the pre-created scripts as provided here: SQL script for creating an ASP.NET Identity Database

I changed the default connection string to the one defined in web.config:

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("MyDatabaseEntities")
    {
    }
}

I foolishly assumed this was all I needed to change since the tables were created and I was pointing it to the SQL database. When I attempt to register a new user, the error message is: {"The entity type ApplicationUser is not part of the model for the current context."}

QUESTION: What am I missing to make this work? Is there a best practice for implementing Identity with existing SQL databases using Entity Framework? Thanks.

3
  • Which version of EF and Code First or DB First? Commented Feb 10, 2014 at 16:51
  • It'll be EF6 using DB first because a SQL database already set up to use EF has been created. Thanks. Commented Feb 10, 2014 at 17:18
  • Please consider inspecting the SimpleMembershipInitializer in Filter folder and UsersContext in Model. The sql script for identity miss some tables use by Membership Provider. Commented Feb 10, 2014 at 17:32

2 Answers 2

2

You can use ASP.NET Identity Database for that.Which is a SQL Database project template for Visual Studio which can be used to create a custom ASP.NET Identity / Membership provider using Database First development approach.

Please check below mnetioned link for more info :

ASP.NET Identity Database

Sign up to request clarification or add additional context in comments.

1 Comment

I have found this recently. It creates the database just like the link that I posted above except it has more fields in the User table. It is something that I was planning on doing as well but this is already done which is great. The problem that I'm getting is "ApplicationUser". So i'm not connecting properly. Are there any configurations that I'm missing? Thanks.
2

We decided that since we would be creating a new database that we would just follow the code-first approach.

For those interested I found this Use ASP.NET Identity on existing DB-Model and it is VERY good. I tried following it but got stuck right at the end and didn't want to spend a lot of time on it since CF was decided.

Thanks for the help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.