This project has moved and is read-only. For the latest updates, please go here.

In this tutorial we will set the startup state of the fake database with CSV file.

Effort makes it possible to fill your fake database with data gathered from CSV files. The following lines of code presents a sample CSV file that can be consumed by the Effort provider to fill the Products table.

"1","Chai","1","1","10 boxes x 20 bags","18.0000","39","0","10","False"
"2","Chang","1","1","24 - 12 oz bottles","19.0000","17","40","25","False"

The first line contains the name of the table fields; each remaining line represents a data row. Each table has its own CSV file named as {table name}.csv (e.g. in this case: Products.csv). You can read more info about the CSV format in a separate blog post.

Place the CSV files in a favourable folder and write some code to make Effort to load them.

public IList GetAllProducts()
{ IDataLoader loader = new Effort.DataLoaders.CsvDataLoader(csvFiles) using (NorthwindEntities ctx = Effort.ObjectContextFactory.CreateTransient(loader)) { return ctx.Products.ToList(); } }

This method returns a collection that contains two entities that contains the same data that was specified in the CSV file. Since creating a CSV file manually could be tiresome, Effort provides an easy-to-use tool to export the current state of your entire database into CSV files. More information can be found in another tutorial.

Last edited Nov 10 at 6:18 AM by zzzprojects, version 24


No comments yet.