Question

I created a HibernateMapping in seperated Classes. The Mapping and classes are in one Assembly. The NUnit tests which I use to test this are in an other Assembly. I think I did it like in this post this

class testMapping : ClassMapping<test>{
//myMappings
}

Now I created a mapper and added it to my configuration:

var cfg=new Configuration();
cfg.Configure();
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntries());
var session = cfg.BuildSessionFactory();

but my Mapping is not found. Do I replace the mapper.AddMappings() with:

mapper.AddMappings(New List<SystemType> {typeof(testMapping)});

it will work.

Do I use the GetExecutingAssembly wrong?

I dont want to add ALL my Mappings seperately.

Was it helpful?

Solution

You can add one class to the Addmappings from the assembly that it belongs to.

My config is like this:-

mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes());

Basically I have 50 or so mapping classes but only need to specify the assembly where one of them lives. NHibernate will auto scan that assembly to find the rest. All my mapping and model classes live in a single separate assembly Domain.Model

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top