nss-evening-cohort-3 / capstones

Capstones of Cohort E3
1 stars 0 forks source link

DB seed with Csvhelper #17

Closed SandraJones closed 7 years ago

SandraJones commented 7 years ago

I have one problem, though. I changed my VolunteerContext file to show

public class VolunteerContext : ApplicationDbContext ( instead of just DbContext)

I did this because in my seed file I am getting an error saying

ApplicationDbContext does not contain a definition for 'CharitableOrganizations' and no extension method of 'CharitableOrganizations' accepting a first argument of type ApplicationDbContext could be found are you missing a using directive or assembly reference?

I am pushing it up even though it is not complete just in case you get a moment to take a look. I did it on the repo branch.

SandraJones commented 7 years ago

Here is the file code where the error occurs: protected override void Seed(VolunteerTrack.Models.ApplicationDbContext context) { Assembly assembly = Assembly.GetExecutingAssembly(); string resourceName = "SeedingDataFromCSV.Domain.SeedData.CharitableOrganizations.csv"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { CsvReader csvReader = new CsvReader(reader); csvReader.Configuration.WillThrowOnMissingField = false; var orgs = csvReader.GetRecords().ToArray(); Context.CharitableOrganizations.AddOrUpdate(c => c.Code, CharitableOrganizations); } } Error is under CharitableOrganizations on last line.

jcockhren commented 7 years ago

@SandraJones Let's talk more about this today during class. Going forward, the issues here are only for Capstone pitches, not general help.