About migration of entityframework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.