Entity Framework Code First Seed database

entity-framework-6

Question

I'm utilizing the Code First method with E.F. I must now add some data to the database, however I find it difficult to do so. Something is ambiguous... I searched online, but every solution I came across implied that I should construct a bespoke Initialization, which I do not want to do.

What I need is a technique that will allow me to drop the database, recreate it, and then load it with data each time I run certain tests.

I have made an effort to:

public PublicAreaContext()
    : base("PublicAreaContext")
{
    Database.SetInitializer<PublicAreaContext>(new DropCreateDatabaseAlways<PublicAreaContext>());
}

I then attempted to implement theSeed approach inside theConfiguration class. So:

internal sealed class Configuration : DbMigrationsConfiguration<PublicAreaContext>
{
    protected override void Seed(PublicAreaContext context)
    {
        ...
    }
}

But I never use the seed approach when I try to troubleshoot. I visit the builder ofConfiguration Why is there class but not in the seed?

Thank you for your assistance

1
2
2/11/2016 2:20:59 PM

Popular Answer

ZZZ_tmp
6
2/11/2016 4:06:05 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow