Stored procedures or OR mappers?

后端 未结 15 1266
天命终不由人
天命终不由人 2021-01-06 16:04

Which is better? Or use and OR mapper with SP\'s? If you have a system with SP\'s already, is an OR mapper worth it?

15条回答
  •  再見小時候
    2021-01-06 16:55

    Use stored procedures where you have identified a performance bottleneck. if you haven't identified a bottleneck, what are you doing with premature optimisation?
    Use stored procedures where you are concerned about security access to a particular table.
    Use stored procs when you have a SQL wizard who is prepared to sit and write complex queries that join together loads of tables in a legacy database- to do the things that are hard in an OR mapper.

    Use the OR mapper for the other (at least) 80% of your database: where the selects and updates are so routine as to make access through stored procedures alone a pointless exercise in manual coding, and where updates are so infrequent that there is no performance cost. Use an OR mapper to automate the easy stuff.

    Most OR mappers can talk to stored procs for the rest.

    You should not use stored procs assuming that they're faster than a sql statement in a string, this is not necessarily the case in the last few versions of MS SQL server.

    You do not need to use stored procs to thwart SQL injection attacks, there are other ways to do make sure that your query parameters are strongly typed and not just string-concatenated.

    You don't need to use an OR mapper to get a POCO domain model, but it does help.

提交回复
热议问题