Some times, sample data is important but boring to generate due to many related tables. So, in Entity Framework Code First, I think it's an elegant way to insert them in DropCreateDatabaseIfModelChanges::Seed().
But is there a way to export existing data from database back to a string as C# / VB sentences that insert poco objects?
If it works, we may use it to backup data gracefully, or save to multiple .cs by scenes, switch them as needed to better our test, etc.
var students = new List<Student>
{
new Student { FirstMidName = "Carson", LastName = "Alexander", },
new Student { FirstMidName = "Meredith", LastName = "Alonso", },
new Student { FirstMidName = "Arturo", LastName = "Anand", },
// ...
};
students.ForEach(s => context.Students.Add(s));
context.SaveChanges();
The "Export as C Arrays (packet bytes) file" dialog box Export packet bytes into C arrays so you can import the stream data into your own C program. Export to file: frame chooses the file to export the packet data to. The Packet Range frame is described in Section 5.9, “The Packet Range frame” . 5.7.5. The "Export as PSML File" dialog box
1. Reports The simplest option is to create a report then export the details as .csv. When viewing a report: Choose Comma Delimited .csv as the export file format 2. Data Export The next simplest way to mass export data to .csv is to use the Data Export scheduling tool.
With Aspose.Cells library for .NET, you can easily export data of specific rows and columns from one Excel document to another. The following code sample shows how to do this in C# language. // Open the source excel file. Workbook srcWorkbook = new Workbook ("Source_Workbook.xlsx"); // Create the destination excel file.
If you're new to ADO.NET and DataTable, first read this: DataTable in C# Code: b. Create UI to display DataTable Here we created a simple DataGridView to bind to the DataTable. Code After adding the Extension method the ToCSV method is now appearing in the list below: d. Export to CSV on button click e. Call ToCSV method
As @Luke suggested in his comment. the best way is to generate Json files for your seed data.
in this article, you can find the easy way to generate your Json from SQL query.
Then all you need is to read them by Newtonsoft.Json
e.g.
var countriesStream = new StreamReader(HostingEnvironment.MapPath("jsonFile.json"));
try
{
countriesList = JsonConvert.DeserializeObject<List<Country>>(countriesStream.ReadToEnd());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With