locked
Performance impact of using Entity framework. RRS feed

  • Question

  • User2048898515 posted

    Hi Guys,

    i have a doubt regarding overall performance of using Entity framework.
    Is the Entity framework slower than Dapper or ADO.NET?

    1)if Entity framework slower why we have to use it? Check below links

    https://exceptionnotfound.n...

    https://koukia.ca/entity-fr...

    2) To Update a entity in DB:

    In Entity Framework, first we need to get the entity first which requires SQL query (1 DB Connection), then update the entity (1 DB Connection) totally 2 SQL connection.

    In ADO.NET, we can directly call the sql query/SP so only one DB Connection.

    Friday, November 9, 2018 12:24 PM

Answers

  • User-821857111 posted

    nambir

    Is the Entity framework slower than Dapper or ADO.NET?

    Yes. But the actual difference in performance for most applications is not noticeable.

    nambir

    if Entity framework slower why we have to use it?

    You don't "have to" use it. You can choose to use it if you want to take advantage of its benefits.

    nambir

    In Entity Framework, first we need to get the entity first which requires SQL query (1 DB Connection), then update the entity (1 DB Connection) totally 2 SQL connection.

    Not true. You can use a stub to update an entity:

    var contact = new Contact{Id = 1};
    contact.FirstName = "Something new";
    context.Entry(contact).Property("FirstName").IsModified = true;
    context.SaveChanges();

    When you do it like this, only the FirstName column is specified in the UPDATE statement that EF generates.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 9, 2018 12:35 PM

All replies

  • User-821857111 posted

    nambir

    Is the Entity framework slower than Dapper or ADO.NET?

    Yes. But the actual difference in performance for most applications is not noticeable.

    nambir

    if Entity framework slower why we have to use it?

    You don't "have to" use it. You can choose to use it if you want to take advantage of its benefits.

    nambir

    In Entity Framework, first we need to get the entity first which requires SQL query (1 DB Connection), then update the entity (1 DB Connection) totally 2 SQL connection.

    Not true. You can use a stub to update an entity:

    var contact = new Contact{Id = 1};
    contact.FirstName = "Something new";
    context.Entry(contact).Property("FirstName").IsModified = true;
    context.SaveChanges();

    When you do it like this, only the FirstName column is specified in the UPDATE statement that EF generates.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 9, 2018 12:35 PM
  • User475983607 posted

    nambir

    1)if Entity framework slower why we have to use it? Check below links

    Use an API that meets your performance requirement.  

    nambir

    2) To Update a entity in DB:

    In Entity Framework, first we need to get the entity first which requires SQL query (1 DB Connection), then update the entity (1 DB Connection) totally 2 SQL connection.

    In ADO.NET, we can directly call the sql query/SP so only one DB Connection.

    Entity Framework can also invoke a stored procedure if that's what you are asking.  Reading the Entity Framework reference docs really helps.

    Friday, November 9, 2018 12:39 PM
  • User1520731567 posted

    Hi nambir,

    1)if Entity framework slower why we have to use it? Check below links

    It is not necessary to use it. This is a personal choice. 

    EF makes a lot of things more comfortable when working with databases. There is a lot going on under the hood that you otherwise would have to code manually.

    2) To Update a entity in DB:

    In Entity Framework, first we need to get the entity first which requires SQL query (1 DB Connection), then update the entity (1 DB Connection) totally 2 SQL connection.

    In ADO.NET, we can directly call the sql query/SP so only one DB Connection.

    EF is built on top of using ADO.NET. This means that everthing EF does, add more overhead to whatever ADO would do.

    First time EF loads metadata into memory, that takes a time.

    It builds in-memory representation of model from edmx file, or from source code if you are using code first.

    Actually EF is build at the top of ADO.NET, so it can't be faster. But it makes development much faster. And improves maintainability of your code.

    Here is some discussion about performance:

    https://stackoverflow.com/questions/15107992/performance-analyze-ado-net-and-entity-framework

    Best Regards.

    Yuki Tao

    Monday, November 12, 2018 3:06 AM