This situation: the application has a database with users: admin, moder and user, let's say. I would like to make it so that when the application starts, the table with users is filled with the necessary values, but I don’t have any idea how to do it better: either set up the sid in some way, or connect the SQL script so that it runs after it starts up and populates ...
Please tell me how to act rationally and how best to implement this option.
- What is now used in the application to work with the database? Is there an EF and if there is, what approach to building a database (code-first, db-first)? - Alex Krass
- @AlexKrass, and, yes, local MySQL, EF, the database is created with the code - guitarhero
- 2In EF, you can use the migration mechanism to execute arbitrary code or prepared instructions. You can specify there a script to execute, if each time inside the Configuration class. If once, you can inside the migration after AddMigration. Although it is necessary to work with migrations carefully and they may seem complicated, but try this option. You can also often generate a SQL script from migrations and then just execute it. However, if you are not confident in yourself, do not use this option and just load the EF designer and run SQL. - Alex Krass
- @AlexKrass, good, thanks. I will try) - guitarhero
|