1

I want to implement a new WebApp in an existing MySQL database, the problem appears when I try to do the migration or the connection because I have already an 'Users' table in there, so I want to create my own tables (webapp_users, webapp_roles, ...).

I tried several ways to do it but no one worked, Can you help me and tell me the steps to follow to do this from the 'New > Project...' step?

Should I install the MySQL packages from the NuGet Package Manager, use external tools/addons, ...?

I will appreciate that, I'm completely blocked.

1
  • If you already have an database you can do a database-first approach and generate the EF-model from your database. I am not 100% sure if this is possible with MySQL, but search internet for database-first
    – Ravenix
    Dec 19, 2016 at 8:08

1 Answer 1

2

Create a db in your MySql server with the required tables and follow these steps :

  1. Import MySql.Web, MySql.Data and MySql.Data.Entity.EF6 dlls into your project first.
  2. Now create a Entity framework data model from your database by right clicking any folder -> new item -> Data -> ADO.net entity data model
  3. Click Generate from database -> Next
  4. Click on New Connection -> Change ->
  5. Select MySql Database as datasource
  6. Give your MySql server credentials and select database to generate the data model from database

It should work fine.

Edit : You can also pass the name of the connection string (stored in the web.config) in your context to the base constructor of the IdentityDbContext

public class MyDbContext : IdentityDbContext<MyUser>
{
  public MyDbContext()
    : base("TheNameOfTheConnectionString")
  {

  }
}

Check this for more info

8
  • this works great, but how should I continue to link that to the Identity Storage Model that I want? Dec 19, 2016 at 9:16
  • @JoseMMartin : What do you mean by that?
    – ViVi
    Dec 19, 2016 at 9:37
  • Link the ADO.net Data Model to the Identity, because it's working and I can access to the database but the credentials of the webapp are not saved in the database Dec 19, 2016 at 9:55
  • why do you expect the credentials of the web app to be stored in the database? Are you saving some data and you are not able to fetch it? The db related credentials and info is stored in the Web.config file under connection string.
    – ViVi
    Dec 19, 2016 at 9:58
  • I mean the users, roles, etc tables (The tables that the Identity Storage uses to save the credentials of the users to access the application). Now I can't save them in my own tables, because of the names, as I said in my question I already have a 'Users' table in the db. Should I create the tables with the corresponding format? Dec 19, 2016 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.