Nhibernate 4升级

时间:2015-08-28 13:49:51

标签: c# .net nhibernate nhibernate-mapping nhibernate-4

我正在尝试将NHibernate的现有Web应用程序版本升级到版本4.我遇到类似于this问题的FetchMany问题

我的DAO类错误被抛出:

        var results = CurrentSession.Query<Vehicles>().Where(v => v.Id == vehicleId);

        results.FetchMany(r => r.Vans).ToList();

        results.FetchMany(r => r.Cars)
            .ThenFetch(c => c.Manufacturer)
            .ThenFetch(c => c.Country).ToList();

        results.FetchMany(r => r.Cars) // Error Gets thrown on this line with cannot fetch multiple bags
            .ThenFetch(c => c.Manufacturer)
            .ThenFetch(c => c.Model).ToList();

 //rest of query removed for brevity

public class Vehicles
{
        private IList<Car> _cars = new List<Car>();
        private IList<Van> _vans = new List<Van>();

        public virtual IEnumerable<Truck> Cars { get { return _cars; } }
        public virtual IEnumerable<Van> Vans { get { return _vans.Where(x => x.FuelLevel > 0).OrderBy(x => x.FuelLevel); } }
}

映射hbm xml文件

<bag name="Cars" cascade="all-delete-orphan" access="field.camelcase-underscore" inverse="true">
  <key column="CarId" />
  <one-to-many class="Car" />
</bag>

<bag name="Vans" cascade="all-delete-orphan" access="field.camelcase-underscore" inverse="true">
  <key column="VanId" />
  <one-to-many class="Van" />
</bag>

在DAO类中重写查询的正确方法是什么,以便正确返回结果集?是否需要在nhibernare映射文件中更新任何内容?

0 个答案:

没有答案