Has anyone published a generic database initializer capable of taking an XML file (or other file representation) of database contents and using it to initialize a code-first database in the Seed method?
I’m thinking of something that uses Reflection to populate the database. I realize there is a lot of fun to be head with FK relationships, but if such a tool existed, especially if it was bi-directional, it would be very handy. Unfortunately my google-fu is failing me.
Just wanted to make sure I wasn’t missing something…I’ve got an awful lot of init code I could throw away…
Are you talking about the actual data itself? In that case, XML and reflection would be overkill. Just put the data in the DB, and the re-export your INSERT statements:
What is the best way to auto-generate INSERT statements for a SQL Server table?
Then, in your Seed methods (or InitializeDatabase()), read in your exported file and use context.Database.ExecuteSqlCommand().