c**t 发帖数: 2744 | 1 Can any nHibernate expert let me know what's wrong with the following? I
alwasy got Acccount.ListAttr as null; when do "foreach(var a in Account.
ListAttr)" I got invalid cast error: can't cast ISet to IList..
I have Account.hbm.xml as follows:
...
..
and Account.cs has:
public virtual ISet ListAttr {get; set; }
..
Also have SomeOtherClass.hbm.xml:
...
select Col1, Col2 from SomeTable where attr=?
and SomeOtherClass.cs
public virtual String Col1 {get; set; }
public virtual String Col2 {get; set; }
public virtual int SomeId {get; set; }
.. | c**t 发帖数: 2744 | 2 其实就是根据Account table中的一个field去query一组tables得到一组数据: ISet<
CustomClass> ListAttr。 | s***o 发帖数: 2191 | 3 if you are using .NET 4, then there are two ISet available.
One is from System.Collections.Generic, and the other is from Iesi.
Collections.Generic. Maybe there is a type mismatch here? | c**t 发帖数: 2744 | | c**t 发帖数: 2744 | 5 using profile, I figured what went wrong. I have Account.hbm.xml as
...
The issue was nHibernate always passes in "Account_Id" for my sql-query...
it's not SomeId. | c**t 发帖数: 2744 | 6 It's mapping issue:
WARN:
System.IndexOutOfRangeException: Unable to find specified column in result
set
at Oracle.DataAccess.Client.OracleDataReader.GetOrdinal(String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[]
names, ISessionImplementor session, Object owner)
at NHibernate.Type.ManyToOneType.Hydrate(IDataReader rs, String[] names,
ISessionImplementor session, Object owner)
at NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(
IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][]
suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session)
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i,
Object obj, String instanceClass, EntityKey key, LockMode lockMode,
ILoadable rootPersister, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i,
ILoadable persister, EntityKey key, LockMode lockMode, EntityKey
optionalObjectKey, Object optionalObject, IList hydratedObjects,
ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters
, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey,
LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet,
ISessionImplementor session, QueryParameters queryParameters, LockMode[]
lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey
[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(
ISessionImplementor session, QueryParameters queryParameters, Boolean
returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters) |
|