Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I review an existing project, how to determine if it is EF Code First, or Model First, or DB First?

I am reviewing an existing ASP.NET MVC (5.2.3) EF (6.1.3) project.

The project uses ASP.NET Identity, and I reviewed the 2 connection strings in web.config, one for the ASP.NET Identity and one for EF. Both points to the same DB, I've successfully modified them to let's call "mydb" I've also reviewed the mydbModel.edmx project item.

When I run the project, the mydb automatically created with the ASP.NET identity tables in it (as expected), however the other tables (for entities defined in mydbModel.edmx) are not. No error message, except later the application does not find a table.

Further I found the following lines too, so I suppose it is definitely not Code First:

public partial class MyDbEntities : DbContext
{
    public MyDbEntities()
        : base("name=MyDbEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

Although I am working with EF since its advent, (mainly DB First) unfortunately I am not sure the other main methods and their variants.

What else should I examine to make sure what kind of concept the project is using, and how can I create the tables defined in model?

like image 929
g.pickardou Avatar asked Nov 09 '22 18:11

g.pickardou


1 Answers

By the code you have posted it definitely looks like DB first because we will use DbModelBuilder to configure entities in OnModelCreating in Code First. Also Code first doesn't have any edmx file (we don't have any in our project).

like image 113
ManojAnavatti Avatar answered Dec 03 '22 00:12

ManojAnavatti