Why is ORM considered good but “select *” considered bad?

后端 未结 12 1667
误落风尘
误落风尘 2021-01-29 23:25

Doesn\'t an ORM usually involve doing something like a select *?

If I have a table, MyThing, with column A, B, C, D, etc, then there typically would be an object, MyThin

12条回答
  •  鱼传尺愫
    2021-01-30 00:10

    If you feel the need to encapsulate everything within an object, but need something with a small subset of what is contained within a table - define your own class. Write straight sql (within or without the ORM - most allow straight sql to circumvent limitations) and populate your object with the results.

    However, I'd just use the ORMs representation of a table in most situations unless profiling told me not to.

提交回复
热议问题