NHibernate 异常及解决办法(长期添加中)
Mapping 錯誤:
?
1) Could not determine type for:Namespance.Class,AssemblyName, for columns: NHibernate.Mapping.Column(ColumnName)
通常是Mapping中的 type attribute設定錯誤,在Assembly找不到。如
<property name="PropertyName" column="ColumnName" type="Namespance.Class,AssemblyName">
如果沒有column , 那么就是 PropertyName作為ColumnName。
?
2)The following types may not be used as proxies: 
Namespance.Class: method methodName should be 'public/protected virtual' or 'protected internal virtual'
Namespance.Class: type should not be sealed
類中的 public/protected 方法沒有使用 virtual 修飾,加上virtual就可以了。因為NHibernate 對于Many-to-one的one方,采取了lazyLoad,因此在加載Many的時候,會為one這生成Proxy類,因此One不能是一個seald類,并且所有公開方法都需要使用virtual, 如Child的屬性Parent,如果想獲得Child的時候,不加載Parent數據,那么Parent必須符合以上的規則。
另外一種辦法是,把one一段的對象設定為<class lazyLoad=false>
?
3)NHibernate.PropertyNotFoundException: Could not find a getter for property 'Id' in class 'Namespance.Class,AssemblyName'. 
?找不到屬性 Id的 getter,這個getter也可以換成為setter。 補充get 和 set,就可以解決。 
?
4)?These classes referenced by 'extends' were not found:
FullName:Namespace.class - Name:class
在繼承映射中,如subclass ,需要一個Extends的 attribute,但是這個extends所指向的父類的名稱,在mapping中并不存在。填寫正確的 extends就可以。?
?
5)?MappingException: An association from the table Crimson_Info refers to an unmapped class: Crimson.Contents.Content?
轉載于:https://www.cnblogs.com/fantasylu/archive/2010/04/21/1717324.html
總結
以上是生活随笔為你收集整理的NHibernate 异常及解决办法(长期添加中)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 莫烦python视频顺序_莫烦Pytho
- 下一篇: 2022年江西省研究生数学建模竞赛冰壶运
