Entity Framework – Type Checking and Verification System for Database Code

cdatabaseentity-frameworkorm

When I read pro and con lists of using Entity Framework (or any modern ORM really), I'm surprised that the following point doesn't arise (self quote):

Using strongly-typed domain entities allows for type checking at
compile-time which essentially performs a verification of all your
database operations. This is something that is not possible with
ADO.NET (whether using inline SQL or stored procedures).

For me, this is one of the biggest advantages of using an ORM. An issue that I come across regularly when dealing with ADO.NET based applications are the run-time errors from SQL. Static checking completely eliminates this.

Could anyone elaborate as to why this isn't hugely relevant to many developers? It appears that some don't even agree with the above statement.

Example of some pro & con resources:

Best Answer

What you mentioned about Entity Framework happens only if you're model is up to date (in data-driven design). If not, you won't get a compile-time error, and they would definitely defer to become run-time errors.

Consider this scenario. You create a database, with one table called Users which has 3 columns: Username, Password, IsActive.

You create a project, and add an Entity Framework .edmx file to it, updating it with the schema of your database. Great till here.

Now what happens if someone change the data type of the IsActive column from Boolean to int, and you don't know about it?

You simply build your project (which builds successfully) and run it, and then you get some errors.

In model-first and code-first development models, the scenario is even worst, as there is no direct and auto-generated mapping between your domain model and database schema.

Thus by the experience I've got till now, I can't say that Entity Framework definitely helps you get mapping problems at compile time. The only case it can help, is to let it generate the model itself from database, and get updated.

Related Topic