The code first of EF was used in the recent project. I didn't know it at the beginning, so I didn't elaborate on it. I found several problems and recorded them. Let's take a look at them later:
1. When there are multiple to multiple tables, configuration should not be less configured. It is quite simple to find the primary key and foreign key relationship between the corresponding tables and configure them through fluent API.
1 modelBuilder.Entity<EquipmentClassPropertyType>()2 .HasMany(m => m.EquipmentCapabilityTestSpecification)3 .WithMany(m => m.TestedEquipmentClassProperty)4 .Map(m =>5 {6 m.ToTable("T_Equipment_EquipmentClassAndSpec");7 m.MapLeftKey("EquipmentClassPropertyID");8 m.MapRightKey("EquipmentCapabilityTestSepcID");9 });
There is a list of each other in both corresponding classes to form multiple-to-many relationships. Key: The corresponding class cannot have the same foreign key, which leads to new problems;
2. About the configuration file:
When writing a program, you can directly put the name of the data connection string link in xxxcontext, which saves more effort;
3. it was about data migration and change. At the beginning, we killed the database every time and found this was a problem. Later we went to see migration, which was quite simple; that is, just a few code statements, like the CMD Command, are super simple:
1 enable-migrations // start database migration 2 Add-migration addnewclass // Add a new class to complete data change, however, this operation only suspends 3 Update-database // writes the pending operation to the database, and implements change 4 Update-database-targetmigration: $ XXXX 5 // reads the original change parameters, restore original data
For more complex commands, please refer to the official documentation...
About migration of entityframework