In the java JPA, if we need to create an entity mapping to database, we just use annotation, @entity
, it is almost codeless. In the C#/NHibernate, do we have the similar ?
Thanks
There are NHibernate mapping attributes, however I don't think anybody really uses it. Currently we have many options to do NHibernate mapping. Besides standard .hbm.xml mappings, there are FluentNHibernate and, as of NHibernate 3.2, mapping by code.
If you don't want to use .hbm.xml mapping, I would suggest FluentNHibernate or mapping by code. FluentNHibernate is older, has a solid wiki for documentation and is generally easier to find examples online.
Mapping by code is newer and it comes with NHibernate (no additional assemblies). You can start looking here for documentation.
Both NHibernate and mapping by code have concept of auto-mapping using conventions. They will scan over your assemblies in search for entities and map them using default or custom conventions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With