I am trying to use Seed (using an external source, which is a CSV file), an Azure SQL database associated with an Azure site.
I can use the database in the development environment using the EF Migration Seed method and the CSV file as specified in the Migration.cs file. Note: The CSV file in the project in Visual Studio is set to Action for the embedded resource.
public void SeedData(WebApp.Models.ApplicationDbContext Context)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string resourceName = "WebApp.SeedData.Name.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 records = csvReader.GetRecords<Products>().ToArray();
foreach (Product record in records)
{
Context.Products.AddOrUpdate(record);
}
}
}
Context.SaveChanges();
}
When I deploy to Azure from VS2013 and select Execute Code First Migration, the database is not seeded.
UPDATE
Now it works. After I completed a clean build, then I built the project, and then deployed the website, selecting "Run the first code read."