Search code examples
c#entity-frameworkef-code-firstdb-first

How to know project is code-first or database-first?


In an existing project, how do I know if it's code-first or database-first?

Project has this lines of code:

public class TestDBContext : DbContext
{
    public DbSet<Player> Players { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

And project has no .edmx file. If any other details need I will share.

EDIT:

Player.cs class

public class Player
{
    public int PlayerID { get; set; }
    public string PlayerName { get; set; }
}

EDIT 12.05.2017

IF I change database name from connection string and run project, it creates database with the new name with all tables. May be this will be hit for the answer.


Solution

  • If this is a project is Database-first, there is :


    • [name].edmx diagram file and with it, [name].Context.tt & .cs
    • every tables that are translated into class are hidden in tree like .edmx > .tt
    • in OnModelCreating, there is a throw new UnintentionalCodeFirstException()

    If not, all the class issue from the tables are in the project (no tree).