Connect ASP.net Identity 2.0 to an Existing Database

I am using vs2013 and am using asp.net mvc 5 to build my web application. to do individual authentication, I use Identity 2.0 .
when I created my Entitymodel.edmx, it automatically generated a new connection string for my db in web.config, as here:

<add name="myEntities" connectionString="metadata=res://*/Models.mEntity.csdl|res://*/Models.mEntity.ssdl|res://*/Models.mEntity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\Shop.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Suppose Identity uses the first code approach to the mak database and is connected to another connection string (DefaultConnection), for example:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-testauthentication-20151116011628.mdf;Initial Catalog=aspnet-testauthentication-20151116011628;Integrated Security=True"
      providerName="System.Data.SqlClient" />

since the result when you first start the project creates a new .mdf file with the name

ASPnet-testauthentication-20151116011628.mdf

and create tables in it. but I want Identity to connect to my already created db with the name: Shop.mdf and create its table in it. so I put the connection string name in the class ApplicationDbContextin IdentityModel.cs, like here:

public ApplicationDbContext()
        : base("myEntities", throwIfV1Schema: false)
{
}

but I get the following error:

The ApplicationUser object type is not part of the model for the current context.

So what is the right and right way to do this?

Many thanks

UPDATE:
I created an Identity table with exactly the same name in my existing database and DefaultConnection to connect to the existing database, and now I get this Error:

'c:\users\mohamad\documents\visual studio 2013\Projects\Shop\Shop\App_Data\Shop.mdf', . . CREATE DATABASE . .

, ,

:
1: , , .

2: , : , , :

  • model.edmx
  • model.edmx
  • edmx- Connection,
  • DefalutConnection .mdf, Entity Connection.
  • , .

, Identity, name, City .... :

  • IdentityModel.cs ApplicationUser:

    public class ApplicationUser : IdentityUser { public string Adress { get; set; } public DateTime DateOfBirth { get; set; } .... }

  • AccountViewModel.cs RegisterViewModel [Requierd]
  • in AccountController.cs Register , :

    var user = new ApplicationUser() { UserName = model.Email, Email = model.Email ,Adress=model.Adress};

  • html

+4
1

. Identity , First, Identity . .

Identity, , . , Identity.

, . Code First, , Identity EDMX.

, , EDMX . , EF7. EF EF6 , - . , Code First , EF.

+1

Source: https://habr.com/ru/post/1617120/


All Articles