![]() I choose to name the table for seeding history track _SeedingHistory. This is quite straight forward and it can be easily replicated. Tracking of executed seeding scriptsĮF Core migration keeps tracking of executed migrations in _EFMigrationsHistory by adding a new record for every migration file that was successfully executed. ![]() ![]() Luckily this is not hard to replicate and we'll go through it in the rest of the article. What we are loosing with this approach is out of the box mechanism to take care of single seeding script execution which we have using migrations. If you check the solution, you will see that comparing to the previously mentioned approach, migration classes and SQL scripts are separated completely into separate folders under data infrastructure project. To avoid unnecessary complexity I did not include application layer (with services) and data layer (repositories), but you should consider adding these projects to your real world application solution I'll use a simple solution which you can find on Github to demonstrate SQL scripts approach. On a good side you have EF Core migrations mechanism making sure your seeding migration executes only once by adding a record to _EFMigrationsHistory table. The biggest problem is that EF Core does not let you target only specific columns, but rather tries to map all columns to the entity model class. This causes some of the seeding migrations to fail due to structure changes either during compilation or runtime. The biggest problem with approach described in Seeding data with Entity Framework Core using migrations article is that data structure migrations and seeding migrations are executed at the same time simultaneously. This will ensure that all structural changes are performed before any data is seeded. This allows you to separate completely data structure setup (migrations) and data seeding. Unfortunately, you cannot skip some columns when mapping entities to tables and this is where this approach becomes a bit hard to maintain.Īnother approach which I also used to overcome these issues is using good old plain SQL script files to seed the data. This does not cause compilation error, but rather runtime because your migration that seeds may try to set some columns that may be created in the table in the migration that executes later. However in some corner case, when you are changing the table structure of the tables which are also involved in seeding process you may end up in compilation errors because you are referencing table columns in your seeding which may not exist anymore.Īnother type of error that may occur due to table structure changes is when you try to execute migrations from the scratch, to an empty database. In large number of cases this approach works just fine and you do not need to do any adjustments or add any additional tables, just use migrations mechanism out of the box. This approach relies on EF Core migrations to ensure seeding of specific data is done only once using _EFMigrationsHistory table to track structural migrations as well as data seeding migrations. Please refer to the Website Terms of Use for more information in this regard.Not so while ago I wrote an article on Seeding data with Entity Framework Core using migrations. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. ![]() Please refer to the Website Terms of Use for more information in this regard.Ĭonfindential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Disclaimer: The information provided on and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |