Base solution for your next web application
Open Closed

Add Existing Tables (PK - TableNameId) #3609


User avatar
0
bbakermmc created

Whats the preferred way to add existing tables that aren't managed via EF Migrations.
I need to add about 100 tables to use. The DBMs also set them up as TableNameId and not Id.

Can I just create another Context that uses the same connection string from the base Dbcontext?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @BBakerMMC,

    Yes, you can create a seperate DbContext and map it to same db using same connection string. If you want to use another field instead of Id, in your case it is better to map Id field to TableNameId like this:

    modelBuilder.Entity<YourEntity>().Property(x => x.Id).HasColumnName("TableNameId ");
    

    Thanks.