Stored Procedure vs Linq

Some advantages of LINQ over sprocs:

  1. Type safety: I think we all understand this.
  2. Abstraction: This is especially true with LINQ to Entities. This abstraction also allows the framework to add additional improvements that you can easily take advantage of. PLINQ is an example of adding multi-threading support to LINQ. Code changes are minimal to add this support. It would be MUCH harder to do this data access code that simply calls sprocs.
  3. Debugging support: I can use any .NET debugger to debug the queries. With sprocs, you cannot easily debug the SQL and that experience is largely tied to your database vendor (MS SQL Server provides a query analyzer, but often that isn't enough).
  4. Vendor agnostic: LINQ works with lots of databases and the number of supported databases will only increase. Sprocs are not always portable between databases, either because of varying syntax or feature support (if the database supports sprocs at all).
  5. Deployment: Others have mentioned this already, but it's easier to deploy a single assembly than to deploy a set of sprocs. This also ties in with #4.
  6. Easier: You don't have to learn T-SQL to do data access, nor do you have to learn the data access API (e.g. ADO.NET) necessary for calling the sprocs. This is related to #3 and #4.

Some disadvantages of LINQ vs sprocs:

  1. Network traffic: sprocs need only serialize sproc-name and argument data over the wire while LINQ sends the entire query. This can get really bad if the queries are very complex. However, LINQ's abstraction allows Microsoft to improve this over time.
  2. Less flexible: Sprocs can take full advantage of a database's featureset. LINQ tends to be more generic in it's support. This is common in any kind of language abstraction (e.g. C# vs assembler).
  3. Recompiling: If you need to make changes to the way you do data access, you need to recompile, version, and redeploy your assembly. Sprocs can sometimes allow a DBA to tune the data access routine without a need to redeploy anything.

Security and manageability are something that people argue about too.

  1. Security: For example, you can protect your sensitive data by restricting access to the tables directly, and put ACLs on the sprocs. With LINQ, however, you can still restrict direct access to tables and instead put ACLs on updatable table views to achieve a similar end (assuming your database supports updatable views).
  2. Manageability: Using views also gives you the advantage of shielding your application non-breaking from schema changes (like table normalization). You can update the view without requiring your data access code to change.


要查看或添加评论,请登录

Mohamad Anouti的更多文章

  • The Global Job Market: A Decade of Disruption

    The Global Job Market: A Decade of Disruption

    As I turn 36, I can't help but reflect on the past five years, which have been marked by unprecedented global turmoil…

  • The Paradox of Remote Hiring: A Global Talent Pool or a Domestic Focus?

    The Paradox of Remote Hiring: A Global Talent Pool or a Domestic Focus?

    The rise of remote work has undeniably reshaped the global job market, promising unprecedented access to talent from…

    2 条评论
  • Recruitment Reality Check

    Recruitment Reality Check

    The recruitment landscape has become increasingly complex and frustrating for employers with specific hiring needs…

  • Moving Database To Another Location in SQL Server

    Moving Database To Another Location in SQL Server

    Error: Unable to open the physical file. Operating system error (Access is denied.

  • Is a College Degree Worth It Anymore? The Frustrations of a Changing Job Market

    Is a College Degree Worth It Anymore? The Frustrations of a Changing Job Market

    The dream: years of studying, a prestigious degree, and a fulfilling career with a salary that reflects your hard work.…

  • Is Job Stability Still a Thing?

    Is Job Stability Still a Thing?

    In today's ever-changing job market, the concept of "job stability" seems almost mythical. But fear not, career…

  • Trying to fly before you can walk

    Trying to fly before you can walk

    An anti-pattern that I’ve observed is Trying to fly before you can walk. It occurs when an organization attempts to…

  • Software Testing Approaches

    Software Testing Approaches

    Carry Tests Throughout the Software Development Cycle Testing only on the QA stage of the software designing process is…

  • Spaghetti Code

    Spaghetti Code

    Spaghetti Code is a programming anti-pattern in which code becomes almost impossible to maintain or change due to…

  • Code Quality Versus Fast Delivery

    Code Quality Versus Fast Delivery

    One of the responsibilities it states for the Scrum Master is: “Helping the Development Team to create high-value…

社区洞察

其他会员也浏览了