NHibernte Fluent 与 XML 映射
我看到围绕 NH Fluent 接口产生了很多讨论,那么使用 Fluent 代替 XML 映射和 Criteria API 有什么好处呢?
I see a lot of buzz generated around NH Fluent interface, so what is the benefit of using Fluent instead of XML mapping and Criteria API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现最有用的是 Fluent NH 中的 AutoMapping by convention 功能。基本上它会为您映射所有内容,如果您需要一些复杂的映射,那么您可以通过属性覆盖它。
鉴于您只需在实体文件夹中添加新实体并开始使用它,而无需进行映射,这通常是随之而来的。
What I found most useful is AutoMapping by conventions feature in Fluent NH. Basically it maps everything for you, and if you need some complex mapping then you can override it by property.
Given that you can just add new Entity in your Entities folder and start using it, without mapping fuss, that usually comes with it.
需要明确的是,您正在谈论 FluentNhibernate 映射库,对吗?它与查询无关,因此可以与 hql 或
我要求的条件 api 一起使用,因为条件 api 遵循 Fluent接口模式,因此可能被认为是 Fluent NH。
Criteria 与 Hql 的优点和缺点很多,但基本上 ICriteria 更适合以编程方式构建查询,而如果给定的查询永远不会改变(参数除外),则 hql 更好。恕我直言。您还可以使用 hql 执行一些使用标准 api 无法执行的操作,例如分组和不相关的连接。
Just to be clear you're talking about the FluentNhibernate mapping library right? It's not related to querying so it can be used with hql or the criteria api
I ask because the Criteria api follows the fluent interface pattern and so might be considered Fluent NH.
The pros and cons of Criteria vs Hql are numerous but basically ICriteria is better for programmatically building your queries and hql is better if the given query will never change (excepting parameters) IMHO. You can also do a few things with hql like grouping and unrelated joins that you can't do with the criteria api.