locked
Store Linq statement in the database RRS feed

  • Question

  • User-1188570427 posted

    Is it possible to write a linq statement, store it in the database and then have Entity Framework read that in and process it via Entity Framework?

    We are currently running normal sql statements in the database, but it is VERY slow on large queries. 

    Saturday, February 10, 2018 12:29 AM

Answers

  • User1120430333 posted

    Is it possible to write a linq statement, store it in the database and then have Entity Framework read that in and process it via Entity Framework?

    No, Linq is part of the .NET Framework used by C# or VB.NET that would be used in the hosting or hosted assembly such as an exe or a DLL.

    We are currently running normal sql statements in the database, but it is VERY slow on large queries. 

    Linq and EF would be even slower. I doubt that the T-SQL query is slow. What I suspect is slow is the dataset and datatable being used to hold the results of the T-SQL query. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 10, 2018 10:44 AM
  • User753101303 posted

    Hi,

    EF ends up in running SQL as well as it's unlikely a way to solve your issue. You should understand first what happens. Maybe you are missing indexes or just try to load too much data ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 12, 2018 12:29 PM

All replies

  • User1120430333 posted

    Is it possible to write a linq statement, store it in the database and then have Entity Framework read that in and process it via Entity Framework?

    No, Linq is part of the .NET Framework used by C# or VB.NET that would be used in the hosting or hosted assembly such as an exe or a DLL.

    We are currently running normal sql statements in the database, but it is VERY slow on large queries. 

    Linq and EF would be even slower. I doubt that the T-SQL query is slow. What I suspect is slow is the dataset and datatable being used to hold the results of the T-SQL query. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 10, 2018 10:44 AM
  • User-1838255255 posted

    Hi tvb2727,

    According to your description, i think you want to use linq statement to operate database instead SQL statement, so you could check the following sample tutorials:

    Saving Data in the Connected Scenario:

    http://www.entityframeworktutorial.net/crud-operation-in-connected-scenario-entity-framework.aspx 

    Entity Framework CRUD: Select Insert Edit Update Delete using Entity Framework in ASP.Net: 

    https://www.aspsnippets.com/Articles/Entity-Framework-CRUD-Select-Insert-Edit-Update-Delete-using-Entity-Framework-in-ASPNet.aspx 

    Best Regards,

    Eric Du 

    Monday, February 12, 2018 10:49 AM
  • User753101303 posted

    Hi,

    EF ends up in running SQL as well as it's unlikely a way to solve your issue. You should understand first what happens. Maybe you are missing indexes or just try to load too much data ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 12, 2018 12:29 PM