I want to change table name of my c# class by fluent API that it'll must be map on database (SQL Server), and I am using Entity Framework code first as ORM in my project.
Asked
Active
Viewed 226 times
-3
-
Put some considerable code also. – Rajan Mishra Oct 08 '18 at 09:06
-
1Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Aman B Oct 08 '18 at 09:07
-
1Possible duplicate of [Entity Framework Code First - Changing a Table Name](https://stackoverflow.com/questions/21656617/entity-framework-code-first-changing-a-table-name) – ste-fu Oct 08 '18 at 09:29
1 Answers
-1
For do that, you can create a folder as a configuration or mapping in your Data model layer, and then add a class like 'className+"Config".cs'. Then inherit that class form 'EntityTypeConfiguration<"MainClassName">' Then in that class you must create a constructor as same as a 'className+Config', and in this constructor you may use:
this.ToTable("Your_table_name_In_Sql", schemaName: "Your_Schema_name");
After all of them, add your 'className+Config' class to your "DbContext" class As i Mentioned below:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new 'className+Config'());
base.OnModelCreating(modelBuilder);
}

babak jafari
- 32
- 1
- 1
- 9