none
Is entity framework good for complicated queries? RRS feed

  • Question

  • When i am trying to update data from c# code, I always call a stored procedure to do that. Is it convenient to use entity framework to update data without calling stored procedures? I know if we just need update a table or two tables, it's easy to use entity framework to save the table entities. But what if we have complicated logic involving multiple tables in the stored procedure? Is it better to use entity framework, or just call a stored procedure? My understanding is that: entity framework is transferring the logic from stored proc to c# code. am i right? thanks
    Monday, October 2, 2017 8:58 PM

All replies

  • Entity Framework does not do the query. EF uses SQL the same as a stored procedure. The reason a stored procedure is often more efficient is because the query is executed in the server. If a stored procedure is not used then all the data must go to the client from the server. It is not a function of complexity; it is a function of the amount of data. If a single update affects (including just reading) multiple records then not using a stored procedure means that all the records must go from the server to the client and possibly back.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, October 3, 2017 12:27 AM
  • Hi Steve Parker1999,

    Thank you for posting here.

    According to your question is more related to EF, I will move it to ADO.NET Entity Framework and LINQ to Entities forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions. 

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 4, 2017 1:57 AM
  • When i am trying to update data from c# code, I always call a stored procedure to do that. Is it convenient to use entity framework to update data without calling stored procedures?

    EF engine generates T-SQL to be submitted to the DB engine that is executed by the internal stored procedure used the DB engine.

    But what if we have complicated logic involving multiple tables in the stored procedure?

    EF should be able to do the same using Linq that generates the T-SQL.

    Is it better to use entity framework, or just call a stored procedure?

    EF is not a panacea,  and in some situations, a stored procedure muse be used. EF can make the call to the stored procedure. 

    My understanding is that: entity framework is transferring the logic from stored proc to c# code. am i right? thanks

    EF is an ORM.

    https://en.wikipedia.org/wiki/Object-relational_mapping

    I always use DB first, and I find Code first not suitable for complicated DB schemas. I also find Code first not suited for developers that don't have basic DBA expertise.

    http://janheggernes.net/post/entity-framework-code-first-or-database-first

    Wednesday, October 4, 2017 5:54 AM