What is the "Entity" referenced in the free Nhibernate display configuration?

I'm trying to learn fluent nhibernate better, so I'm building a basic sample application from scratch, instead of using someone else's elses framework. However, I find that I really do not understand what happens when mapping files are assigned. I have seen many code examples that show the same code, but none of this says. There is no description of how it works, it just works. Here is an example of the code that I often see.

return Fluently.Configure()
            .Database(config)
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entity>())
            .BuildSessionFactory();

So, in the sample code, what is Entity? and how does this piece of code work?

Part of me thinks this is the name of the assembly, but seeing how the namespace I use is usually the name of the assembly, the compiler complains that I use the namespace as a type.

I think this is important, and I'm rather confused by what I can’t understand.

thank

+3
source share
2 answers

Add from assembly adds all the mappings in the assembly to which the Entity type belongs. AddFromAssembly will do something according to:

typeof(TEntity).GetType().GetAssembly();

This will lead to the assembly to which Entity belongs, and then will use reflection to find all your mapping classes. Instead of accepting this, why not download the source and take a look at yourself: O)

+2
source

s1mm0t answered your question, but I'll figure it out a little ...

FNH , Entity - , Id, .

, , Entity. , int GUID ..

, , " "...; -)

, ...

, , , , - , . - FNH, . , , , - . , FNH, , .

, - ?

+1

Source: https://habr.com/ru/post/1742358/


All Articles