Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 764
Jimmyt1988 Avatar asked Dec 15 '22 02:12

Jimmyt1988


1 Answers

There are a number of ways to achieve this but one is to specify a Column attribute on the property.

[Column("Title")]

See here for more information

like image 188
Paul Hunt Avatar answered Jan 18 '23 23:01

Paul Hunt