Skip to main content

EF Code-First Approach Vs Database-First Approach

Code-First Approach
Advantages
  1. No need to look at the database for any changes in the tables as we can do those in our domain models and these will be migrated to the database.
  2. Provides complete control on each table level of the set, for example, lazy loading, serialization etc.
  3. All changes will be tracked in the database such that we can roll back to any version as needed.
  4. We don’t need any heavy .edmx files and T4 script executions.
  5. Can do changes in the database with no data loss (this feature is available since EF 4.3).
Disadvantages
  1. If there are some 100’s of tables, we need to manually create the domain models.
  2. Writing database objects like Stored Procedures, triggers are complex.
  3. If there is any modification done in the database, it won’t reflect on the entities in the application.
  4. Should have the good C# knowledge to write code while Migrations.
  5. Not preferred for data-intensive applications.
Database First Approach
Advantages
  1. Easy to create Domain Models as this will be automatically created while creating an edmx file using T4 scripting.
  2. Visual Studio provides GUI to configure and add database via. Edmx file.
  3. Good for larger applications.
  4. Any change at database side can be easily updated with a single click at application end.
  5. Can use an existing database.
Disadvantages
  1. Based on database tables, the edmx file will keep growing.
  2. Creating/managing associations, foreign keys, constraints will be more difficult.
  3. If the database is large, it is not easy to maintain or update the edmx file.

Comments

Popular posts from this blog

Top 10 ASP.NET Web API Interview Questions

What is ASP.NET Web API? ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including: Create resource-oriented services using the full features of HTTP Exposing services to a variety of clients easily like browsers or mobile devices, etc. What are the Advantages of Using ASP.NET Web API? Using ASP.NET Web API has a number of advantages, but core of the advantages are: It works the HTTP way using standard HTTP verbs like  GET ,  POST ,  PUT ,  DELETE , etc. for all CRUD operations Complete support for routing Response generated in JSON or XML format using  MediaTypeFormatter It has the ability to be hosted in IIS as well as self-host outside of IIS Supports Model binding and Validation Support for OD...

Extension methods in C#

Consider the class C# 1 2 3 4 5 6 7 8 9 10 11 12 13          namespace ExtensionMethod      {          public class testClass {              public string sayHello ( ) {              return "Hello" ;            }        }      }     Invoke the above from your form using C# 1 2 3 4 5 6          testClass test = new testClass ( ) ;      MessageBox . Show ( test . sayHello ( ) ) ;     This will show “Hello” in message box. Consider the scenario where you don...

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome...