在ORM中覆盖==运算符有什么优势? [英] What advantage is there to overriding the == operator in an ORM?
本文介绍了在ORM中覆盖==运算符有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
显然,许多ORM都这样做:
Apparently, a lot of ORMs do something like this:
query.filter(username == "bob")
生成类似
... WHERE username = 'bob'
为什么要覆盖 == 运算符,而不要使用诸如以下内容:
Why override the == operator instead of something like:
query.filter(username.eq("bob"))
推荐答案
这是一个主观的问题,但总的来说,我会说前者的语法更加直观,并且由于许多(如果不是大多数)ORM都可以做到这一点通常是这样(使其更加直观).
This is a subjective question, but in general I would say that the syntax for the former is more intuitive, and since many (if not most) ORM's do this it's generally expected (making it more intuitive).
这篇关于在ORM中覆盖==运算符有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文