Is there a way to make class names differ from table names?

We are using a database created several years ago and would like to keep the table names the same.

All of our tables are named: "tbl_Orders", but we would like the class names for the models / controllers / etc. were Orders / OrdersController / etc. We map classes to our tables using the Entity Framework.

Sorry if this was asked before, I tried searching but came up empty-handed ...


After a few years ago and with Scott Chamberlain, we came to the conclusion that both answers are correct. I went ahead and marked Masoud's answer as accepted because that is the route I took. Thanks to everyone who helped (especially Scott).


source to share

2 answers

You can use the following code DbContext

to map all of your objects to tables:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
   // TableNameConvention
                 .Configure(entity => 
                            entity.ToTable("tbl_" + entity.ClrType.Name));





You can use Table attribute or free api to map between table names in your database and class names

public class Blog




All Articles