locked
What is the difference between Code first and Model first approach RRS feed

  • Question

  • User264732274 posted

    i like to know What is the difference between Code first and Model first approach. in case of both model first and code first approach database is created by code. so what is the difference.

    please guide me. thanks

    Saturday, August 29, 2015 7:14 AM

Answers

  • User-698989805 posted

    Check this link and it will give all the answers you wanted:

    http://stackoverflow.com/questions/5446316/code-first-vs-model-database-first

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 30, 2015 8:22 AM
  • User753101303 posted

    Hi,

    Nowadays, the difference is merely about which tool you are more comfortable with to model your db. See http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what-does-code-first-only-really-mean.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 30, 2015 9:12 AM
  • User-1945302256 posted

    wrt to Database creation , here are the differences:

    In Code First,

    • There is no Edmx designer used just like in Model first approach. 
    • The advantage of code first is that We create model classes or Entity classes that represent database structure of the tables and business objects. So any changes made to this class affects database tables and business object at the same time. Where as in model first, any changes to model class or database require Synching of data between the two using Update database from model through context menu in Edmx designer.

    Other differences would be:

    Code first has more control of the model from code.

    In code first approach, If we want the project to be deployed on Azure, the same business classes can be reused to create Azure storage objects.

    Here(Code first) the database is used only for storing the data.

    No manual intervention to DB is required.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 12, 2015 11:58 AM

All replies

  • User2024324573 posted

    Hi Sudip,

    in case of both model first and code first approach database is created by code.

    This is not true.

    In database first, you don't create the database from the code, rather you use existing database and using the EMDX entities you save or retrieve or update data. You cannot create a table in the database using database-first or update any table or properties.

    In Model-first you use the models to create the database.

    Hope this will help.

    Saturday, August 29, 2015 7:22 AM
  • User264732274 posted

    where i said that in db first approach db is created by code. i said

    i like to know What is the difference between Code first and Model first approach. 
    in case of both model first and code first approach database is created by code. so what is the difference.

    i said following in case of both model first and code first approach database is created by code.

    i just like to know the difference between Code first and Model first approach. am i clear?

    Saturday, August 29, 2015 11:23 AM
  • User2024324573 posted

    where i said that in db first approach db is created by code.

    Sorry my misunderstanding, I did not ready it properly.

    i just like to know the difference between Code first and Model first approach. am i clear?

    Code-First/Model-First is synonymous, there are the same, Code-First means you use code to create databases and you write code within a Model that is why it is Model-First. They can be used interchangeably.

    Hope this will help.

    Saturday, August 29, 2015 2:54 PM
  • User-698989805 posted

    Check this link and it will give all the answers you wanted:

    http://stackoverflow.com/questions/5446316/code-first-vs-model-database-first

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 30, 2015 8:22 AM
  • User753101303 posted

    Hi,

    Nowadays, the difference is merely about which tool you are more comfortable with to model your db. See http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what-does-code-first-only-really-mean.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 30, 2015 9:12 AM
  • User-1945302256 posted

    wrt to Database creation , here are the differences:

    In Code First,

    • There is no Edmx designer used just like in Model first approach. 
    • The advantage of code first is that We create model classes or Entity classes that represent database structure of the tables and business objects. So any changes made to this class affects database tables and business object at the same time. Where as in model first, any changes to model class or database require Synching of data between the two using Update database from model through context menu in Edmx designer.

    Other differences would be:

    Code first has more control of the model from code.

    In code first approach, If we want the project to be deployed on Azure, the same business classes can be reused to create Azure storage objects.

    Here(Code first) the database is used only for storing the data.

    No manual intervention to DB is required.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 12, 2015 11:58 AM