Detect If DropCreateDatabaseIfModelChanges Ran?

I am using a CodeFirst approach using EF5.

I was looking at running a DropCreateDatabaseIfModelChanges to fix the database if my model changes, but there is data that needs to be repopulated when it does run.

I figure that I can do an entity count to see if it was run, but I am curious if there was a more elegant way to do this? (Some kind of return value or event that I can have my code look for)

Thanks in advance.


You need to derive from DropCreateDatabaseIfModelChanges and override the Seed method to add data to the context for seeding when the DB is recreated:

public class MyDbInitializer : DropCreateDatabaseIfModelChanges<MyDbContext>

    protected override void Seed(MyDbContext context)


And on your application start set it as the Database initializer:

Database.SetInitializer(new MyDbInitializer());

Need Your Help

Naive-bayes multinomial text classifier using Data frame in Scala Spark

apache-spark text-classification apache-spark-mllib naivebayes

I am trying to build a NaiveBayes classifier, loading the data from database as DataFrame which contains (label, text).

How to populate extra fields with jQuery autocomplete

javascript json autocomplete jquery-autocomplete

I am passing complex JSON data to jQuery autocomplete plugin. And it is working fine so it shows the list of Products.