how to use a different name for my class property than the sql column name

Viewed 5885

For example, if I wanted my class property to be named like this for a laugh:

class Product
{
   [Key]
   int ProductID {get;set;}

   [Required]
   string TitleTOTHEMAX {get;set;}
}

My Sql table has 2 columns "ProductID" and "Title", how do I tell the class's property to map itself to "Title" column considering the "TitleTOTHEMAX" column does not exist :)

3 Answers

You should use Fluent Api with those kind of configuration.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
     modelBuilder.Entity<Product>()
    .Property(x => x.TitleTOTHEMAX )
    .HasColumnName("Title")
}
Related