Why do people use linq to sql?

后端 未结 11 1146
轮回少年
轮回少年 2021-02-04 01:51

Given the premise:

  • There are competent sql programmers (correlary - writing sql queries are not an issue)
  • There are competent application developers (corr
11条回答
  •  孤城傲影
    2021-02-04 02:33

    For very simple queries, the overhead of an extra layer adds to the roundtrip cost. For somewhat more complex queries in normal 'business app' scenarios, the optimizations done by the Linq-to-SQL expression->sql translation magic can often save a lot.

    As an example, I recently did a 1:1 translation of a customer-supplied 1400+ (!) line stored proc to L2S. Not only did it go from 1400 lines of SQL to 500 lines of much more readable, strongly typed, and commented code. It also started hitting the database with an average of ~1500 reads instead of ~30k reads. This is before I even started looking at db-side optimizations - that saving is something I can 100% attribute to L2S's ability to eliminate predicates that can be evaluated client-side.

提交回复
热议问题