开发者

How to use SelectList with nhibernate Queryover?

开发者 https://www.devze.com 2023-03-22 15:28 出处:网络
I have this TimeTable timeTable = null; List<TimeTable> timeTableEventSettings = session.QueryOver<TimeTable>(() => timeTable)

I have this

   TimeTable timeTable = null;

        List<TimeTable> timeTableEventSettings = session.QueryOver<TimeTable>(() => timeTable)
            .Where(Restrictions.In(Projections.Property(() => timeTable.Id), timeTableIds))
            .List<TimeTable>().ToList();

now TimeTable can have Many TimeTableEvents. I would like to just return these but I don't know how.

I would like to do this but it does not work

TimeTable timeTable = null;

    List<TimeTableEvents> timeTableEventSettings = session.QueryOver<TimeTable>(() => timeTable)
        .Where(Restrictions.In(Projections.Property(() => timeTable.Id), timeTableIds))
            .开发者_如何转开发Select(x => x.TimeTableEvents)
        .List<TimeTableEvents>().ToList();

but it does not seem to work.

So I am guessing I need to use SelectList but I don't know how to use it.

Error

NHibernate.Exceptions.GenericADOException was caught
  Message=could not execute query
[ SELECT this_.TimeTableId as y0_ FROM [TimeTable] this_ WHERE this_.TimeTableId in (@p0) ]
Positional parameters:  #0>17
[SQL: SELECT this_.TimeTableId as y0_ FROM [TimeTable] this_ WHERE this_.TimeTableId in (@p0)]
  Source=NHibernate
  SqlString=SELECT this_.TimeTableId as y0_ FROM [TimeTable] this_ WHERE this_.TimeTableId in (@p0)
  StackTrace:
       at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
       at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
       at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
       at NHibernate.Impl.CriteriaImpl.List(IList results)
       at NHibernate.Impl.CriteriaImpl.List[T]()
       at NHibernate.Criterion.QueryOver`1.List[U]()
       at NHibernate.Criterion.QueryOver`1.NHibernate.IQueryOver<TRoot>.List[U]()
       at GetExtraEventSettings(Student student, List`1 timeTableIds) in line 85
       at GetExtraEventSettings(String email) in line 314
  InnerException: System.IndexOutOfRangeException
       Message=Index was outside the bounds of the array.
       Source=NHibernate
       StackTrace:
            at NHibernate.Loader.Criteria.CriteriaLoader.GetResultColumnOrRow(Object[] row, IResultTransformer resultTransformer, IDataReader rs, 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)
       InnerException: 


   public TimeTableMap()
        {
            Id(x => x.Id);
            HasMany(x => x.ExtraEventSettings);

        }

public ExtraEventSettingsMap()
    {
        Id(x => x.Id);
        References(x => x.TimeTable).Not.Update().Not.Nullable();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消