2012-02-02 26 views
6

我必須在我的項目中使用HQL查詢,並且出現錯誤:「實體未映射」。當我們使用Nhibernate 3.2的代碼映射時如何允許auto-imports =「true」?

當我讀nHibernate HQL - entity is not mappednHibernate HQL - entity is not mapped(或其他網站)時,我可以看到我必須在每個類上使用auto-import =「true」。

<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"> ... 

當我們使用帶有nhibernate 3.2的代碼映射時,如何設置此自動導入?

我使用的代碼加載映射:

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

問候

回答

7

你不能直接設置它的映射,通過代碼,但可以修改HbmMapping對象從CompileMappingForAllExplicitlyAddedEntities方法返回,在將其傳遞給Configuration對象之前:

mapping.autoimport = true; 
+1

謝謝。很難通過代碼映射找到所有的東西 – 2012-02-03 09:04:30

+0

爲我節省了一小時挖掘NHibernate代碼 - 謝謝! – Dav 2012-11-23 14:00:21

相關問題