Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 547
kgzdev Avatar asked May 11 '17 14:05

kgzdev


People also ask

What is code first and DB first?

In the code first approach, the programmer has to write the classes with the required properties first, while in the database first approach, the programmer has to create first the database using GUI.

What is code first from database?

Code First allows you to define your model using C# or VB.Net classes. Optionally additional configuration can be performed using attributes on your classes and properties or by using a fluent API.

How do I change database first to code first?

To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add. This will open the Entity Data Model wizard as shown below.


1 Answers

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).

like image 138
Totolouis Avatar answered Oct 06 '22 01:10

Totolouis