Ghini Antonio
Ghini Antonio

Reputation: 3142

Entity Framework Core DB first Mapping columns or tables into properties or class with different names

I use scaffolding after each schema change to keep in sync model and database.

I need to expose some columns with different name at domain level then the name at database level.

For example the column COMPANY_NAME in the table COMPANY_PROFILE at domain level needs to be changed in WorkingCompany and COMPANY_PROFILE be translated in the class Company

Moreover I don't want to lose any changes every time I run the scaffolding

Upvotes: 0

Views: 888

Answers (1)

user4219031
user4219031

Reputation: 307

Use CodeFirst configurations.

public class CompanyConfiguration: EntityTypeConfiguration<Company>
{
   public CompanyConfiguration()
   {        
        this.ToTable("COMPANY_PROFILE");
        this.Property(p => p.WorkingCompany)
                .HasColumnName("COMPANY_NAME");
   }
 }

Upvotes: 1

Related Questions