If you have the following two sheets
public class Main
{
public int id{get;set;}
public string Name{get;set};
public virtual icollection<detail> Details{get;set;}
}
public class Detail
{
public int id{get;set;}
public int mainid{get;set;}
public string Desc{get;set;}
[ForeignKey ("Mainid")]
public virtual Main Main{get;set;}
}
Public dbset<main> Mains{get;set;}
Public dbset<detail> Details{get;set;}
Then in the Package Manager console input: update-database, the MySQL database successfully generated two tables.
One, update report, Table ' {database}.dbo. {TableName} ' doesn ' t exist
This time you find that you need to increase the cascade Delete and update features, OK, modify the detail,
public int mainid{get;set;}
Switch
[Required]
public int mainid{get;set;}
Then in Package Manager console input: Update-database-force
Find such errors: Table ' {database}.dbo. Details ' doesn ' t exist
The problem is in the DBO, where the solution is:
Add-migration-aa
A file such as 201710031324203_aa.cs will be generated with an up method in it, and the dbo will be removed and executed update-database-force will be done.
The possible reason is that the table described by EF when working with SQL Server is: DatabaseName.dbo.TableName is correct, and MySQL cannot have dbo (databasename.tablename), so there is an error.
Second, can not delete from the table
//public dbset<detail> Details{get;set;}
When you log out of details and execute Update-database-force, you will find that the table still exists in the database, with add-migration AA you will find that the content of the method up is empty.
This problem occurs because there is a reference to the table from the main table, which will
//public virtual icollection<detail> details{get;set;}
If you look at it, you can delete the detail table.
Some things to note about EF Code First MYSQL master-slave table design