How to allow auto-imports="true" when we use Nhibernate 3.2's mapping by code?
Asked Answered
M

1

6

I have to use an HQL query in my project and I've an error : "entity is not mapped".

When I read nHibernate HQL - entity is not mapped or nHibernate HQL - entity is not mapped (or other web site) I can read that I have to use auto-import="true" on each class.

<hibernate-mapping
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 namespace="BusinessObjets" assembly="BusinessObjects"
 xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> ...

How can we set up this auto imports when we use mapping by code with nhibernate 3.2 ?

I use that code to load the mapping :

var mapper = new ModelMapper();
mapper.AddMappings(typeof(Repository).Assembly.GetTypes());
return mapper.CompileMappingForAllExplicitlyAddedEntities();

Regards

Madison answered 2/2, 2012 at 15:45 Comment(0)
P
7

You can't set it in mapping-by-code directly, but you can modify HbmMapping object returned from CompileMappingForAllExplicitlyAddedEntities method, before you pass it to the Configuration object:

mapping.autoimport = true;
Pyelitis answered 2/2, 2012 at 19:3 Comment(2)
thank you. it's hard to find all the stuff with mapping by codeMadison
Saved me an hour of digging through NHibernate code - thanks!Muddle

© 2022 - 2024 — McMap. All rights reserved.