Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaquette committed Jun 1, 2014
1 parent e231850 commit b00af25
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ Finally, call the SeedFromResource extension method:

You also have the option to seed from a csv file on disk using SeedFromFile, or from any stream using SeedFromStream.

##Connecting Related Entities
Loading data from a CSV file can be a little more complicated when there are relationships between the entities were are loading. Take Countries and Provinces/States as an example. A Province/State always belongs to a single Country. In this case, create a CSV file that includes the Country Code of the Country that the Province State belongs to:

CountryCode,Code,Name
CA,SK,Saskatchewan
CA,AB,Alberta
US,AZ,Arizona
US,AR,Arkansas
US,CA,California

Now, specify a custom mapping action when seeding from the provinces csv:

context.Countries.SeedFromResource("MyProject.SeedData.countries.csv", c => c.Code);
context.SaveChanges();
context.ProvinceStates.SeedFromResource("MyProject.SeedData.provincestates.csv", p => p.Code,
new CsvColumnMapping<ProvinceState>("CountryCode", (state, countryCode) =>
{
state.Country = context.Countries.Single(c => c.Code == countryCode);
})
);

##Available on Nuget
PM> Install-Package EntityFramework.Seeder.EF6

0 comments on commit b00af25

Please sign in to comment.