Entity Framework with mysql, Table Capitalization issue between linux and windows

后端 未结 4 1696
暗喜
暗喜 2021-02-15 17:07

We are currently developing a product using Code First Entity Framework and Mysql. The development database is hosted in a Windows environement while the production mysql is on

4条回答
  •  伪装坚强ぢ
    2021-02-15 17:48

    Entity Framework will use the same name (capitalization, etc) as is declared for the object. So, for example, if you declare a model object as:

    public class Industry
    {
      public int IndustryID { get; set; }
    }
    

    Entity Framework will look for a table of Industry with a column of IndustryID.

    You can change this by adding annotations to your models. Do the following:

    [Table("industry")]
    public class Industry
    {
      public int IndustryID { get; set; }
    }
    

    By doing this, your objects will still use the appropriate .NET naming scheme, but it will match your corresponding database. You can also change the name of the colunns using ColumnAttribute.

    Alternatively, you could change the table names in MySQL.

提交回复
热议问题