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?
问题:
回答1:
- Refactoring friendly (renames won't break mappings)
- Automappings with configurable conventions
- Intellisense in mappings for your domain
- Compile time validation
回答2:
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.
回答3:
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.