Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 Linux.

The issue I am running into is that tables in mysql are named like this:

 mydatabase.industry
 mydatabase.account
 ...

Entity framework creates a query like this:

  Select * FROM mydatabase.Industry;

Notice the capitalized letter. This works fine on mysql in Windows, but on Linux I get this error:

  Table 'mydatabase.Industry' doesn't exist

Any Ideas?

like image 569
AFrieze Avatar asked Feb 25 '12 16:02

AFrieze


People also ask

Is MySQL case sensitive on Linux?

On Operating Systems like Windows where filesystem is case-insensitive MySQL would be case-insensitive by default. But on operating systems like Linux MySQL is case-sensitive.

How do I ignore a case in MySQL?

Learn MySQL from scratch for Data Science and Analytics If you want case-insensitive distinct, you need to use UPPER() or LOWER().

Can Entity Framework be used with MySQL?

MySQL Connector/NET is compatible with multiple versions of Entity Framework Core. For specific compatibility information, see Table 7.2, “Connector/NET Versions and Entity Framework Core Support”.


1 Answers

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.

like image 91
JasCav Avatar answered Oct 26 '22 23:10

JasCav