I'm looking for a way to feed my Database. I use Microsoft SQL Server Management Studio to navigate through the database. I have many rows on many tables there.
I would like to find a fast way to export this database, and write a script which will feed database on my C# application. I often have to delete my DB and create it with entity framework migrations, and every time the DB is empty. I know it would be easy to do that just from MSSQL, but I want an automated way from code, so that when you start the application, it feeds the DB.
The DB is very big and entities are very complex, with many relationships between them, so I don't want to write a lone a json file which would contain everything. Hopefully there's a tool that can do this!
2条答案
按热度按时间oo7oh9g91#
Best advise i have is writing a seeder that seeds data. Technically you could have it pull data from the MSSQL database but personally i would rather just write seeders that seed the data themselves without the need of a dependency on another service.
brccelvz2#
There are multiple ways to achieve this but as mentioned, you should seed the database. You can write a extension class for the
ModelBuilder
.And within the context class, call the
Seed
method to populate the database.You can read more about data seeding here .