Why do people use linq to sql?

后端 未结 11 1152
轮回少年
轮回少年 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:42

    I keep seeing questions about linq to sql and am wondering if I'm missing something.

    It's not that you're missing something. It's that you have something most shops don't have:

    There are competent sql programmers

    Additionally, in your shop those competent sql programmers prefer to write sql.


    Here's a point by point response:

    There is overhead added to each transaction

    Generally true. This can be avoided by translating the queries before they are needed to run using CompiledQuery for many (but not all!) scenarios.

    There is strong likelihood of performance loss for moderate-complex calculations (DBs are made for processing sets and calculations and had teams of engineers working out optimization - why mess with this?)

    Either you're writing linq, which is translated to sql, and then a plan is generated from the optimizer - or your writing sql from which a plan is generated by the optimizer. In both cases you are telling the machine what you want and it is supposed to figure out how to do it. Are you suggesting that subverting the optimizer by using query hints is a good practice? Many competent sql programmers will disagree with that suggestion.

    There is loss of flexibility (if you want to add another ui (non .NET app) or access method, you either have to put the queries back in the db or make a separate data access layer)

    A lot of people using linq are already SOA. The linq lives in a service. The non .NET app calls the service. Bada-bing bada-boom.

    There is loss of security by not having a centralized control of write/update/read on db (for example, a record has changed - if you allow applications to use linq to sql to update, then you cannot prove which application changed it or what instance of an application changed it)

    This is simply not true. You prove which application is connected and issuing sql commands the same way you prove which application is connected and calling a sproc.

提交回复
热议问题