Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# / NHibernate have annotation? [closed]

Tags:

c#

nhibernate

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

like image 391
user595234 Avatar asked Feb 20 '23 16:02

user595234


1 Answers

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.

like image 97
Miroslav Popovic Avatar answered Feb 27 '23 16:02

Miroslav Popovic