EF CodeFirst advantages and disadvantages

Possible duplicate:
EF 4.1 First Code - First Model / Database

I'm just starting to learn EF 4.0 CodeFirst, I want to hear from experts about What are the advantages and disadvantages of EF CodeFirst?

+4
source share
3 answers

I think each approach is more suitable for different scenarios:

Scenarios in which it is recommended to use Database-first or Model-First:

  • Long-life, stable schema databases
  • Changes to the database and model are incremental
  • You want to see your model in one diagram and update it there
  • You can split your model into non-overlapping charts.

Scenarios in which code is recommended:

  • Model development is carried out by programmers who are not interested in the database.
  • Model classes contain logic
  • Class models have fancy (non-standard) structures
  • The model is divided between many assemblies that are not all known at the time of development (extension)
  • Databases are short-lived (e.g. application runtime)
  • Database may change frequently

If you need a long-term database that is dynamic enough to contain an ever-changing structure, consider the general classes / tables that your model / schema reuses for various / context-sensitive purposes.


Update:

Now I recommend using Code-First for additional cases:

  • If you want to be able to write and quickly and easily run integration tests in LocalDB (instead of working with SSDT)
  • If you prefer to see the model and the mappings in one place instead of navigating through charts and display windows
    • If you want it to be more visible if someone is displaying the properties correctly or not. like concurrencycheck
  • Because you can easily disable schema creation in non-local environments, the nature of the database is less relevant.
+7
source

I have always been a supporter of the Data Centric approach, and I believe that this is where the advantages and disadvantages arise.

If your strengths are in database design and development, it may be easier and more intuitive to design your database schema. However, if you think better in objects and classes, or if you work directly from a class model, you might be better off starting from a CodeFirst perspective.

Personally, I have to make more changes, working from the perspective of CodeFirst, which from "DataFirst" generates my classes.

+5
source

The main difference is that Code First requires that you define everything in the code, while Model / Database first requires that you define everything in XML / Designer and only define minimal things in the code.

For example, if you want a two-way navigation property, then you need to write code for this in each of your objects. This is automatically generated for you when using other methods.

I like the Power Code first gives you, but most of the time I just can't bother to do all this.

For the most part, you get the same thing. It is just how you model it.

Another drawback is that (currently) in the code, when you make changes first, it discards the table and recreates it. Loss of all data (you can, of course, sow the database, but you cannot return data that you could enter manually). This will be allowed when the First First Migrations product is released.

0
source

Source: https://habr.com/ru/post/1390101/


All Articles