micahhoover
micahhoover

Reputation: 2160

MVC 3 EF basic architecture question

I'm an MVC / EF newb.

I've got a few different tables I want in my database: say lemons, sugar, and water.

Should I create three separate models: lemons, sugar, and water or make one big model that defines three different classes (with three separate DBContext classes?) and then scaffold each model?

Right now I'm making separate models, but it looks like I have to end up making three separate databases which seems overkill.

The movie example only has one table, so it doesn't answer my question very well.

Upvotes: 1

Views: 282

Answers (1)

AbdouMoumen
AbdouMoumen

Reputation: 3854

You could have 3 model classes (one for each of your entities)

public class Lemon
{
}

public class Sugar
{
}

public class Water
{
}

and create one DbContext for them:

public class MyContext:DbContext
{
    public DbSet<Lemon> LemonSet
    public DbSet<Sugar> SugarSet
    public DbSet<Water> WaterSet
}

This way, you'll be using EF Code First with 3 model classes and one database

Hope this helps :)

Upvotes: 5

Related Questions