Question

I know how to write some seed code for my app, but I'd love to be able to create the data using the site and then have the seed code generated with the data from the DB. Is this possible? Anything that generates the seed code for you based on the database?

ApplicationPermission appPerm1 = new ApplicationPermission();
appPerm1.Name = "Admin";
appPerm1.PermissionCode = Guid.Parse("32BEDDD6-D52D-4DF6-AD2D-6740CC8C01F3");
context.ApplicationPermissions.Add(appPerm1);
Was it helpful?

Solution

What you're trying to do doesn't sound like a great idea but if you really want to do it you could:

Write a SQL script that will generate the appropriate C# syntax and use the result of that query to paste into your .cs Seed file.

However, if you just want random test data; RedGate have a tool that will generate realistic looking data. http://www.red-gate.com/products/sql-development/sql-data-generator/

If you just want some specific test data, I'd suggest taking the one off hit and writing the seed data manually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top