I am trying to learn fluent nhibernate better so am doing a basic sample application from scratch, instead of using someone elses framework. However, I am finding I really don’t understand what is going on in assigning mapping files. I have seen a lot of code examples which are all showing the same code, but nothing that spells it out. No description of how it works just that it works. Here is a code example that I see often.
return Fluently.Configure()
.Database(config)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entity>())
.BuildSessionFactory();
So in the code example what is Entity? and how does that piece of code work?
Part of me thinks it is the name of the assembly, but seeing as how the namespace I am using is usually the name of the assembly the compiler complains that I am using a namespace as a type.
I feel this is important and am rather flustered by the fact I can’t figure it out.
Thanks
Add from assembly adds all mappings in the assembly that the type Entity belongs to. AddFromAssembly will do something along the lines of:
This will get the assembly that Entity belongs to, it will then use reflection to find all of your mapping classes. Rather than take my word for it why not download the source and take a look for yourself :O)