NHibernate IList to List

前端 未结 3 1718
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 11:27

Hi I am trying to return a collection of building domain.

private long _id;
private string _buildingName;
private IList _rooms;
3条回答
  •  萌比男神i
    2021-01-03 12:03

    Why do you need a concrete List object, when you can do everything you want with an IList?

    If it absolutely has to be a concrete list, you have two options.

    First, simply cast the IList to List. This will only work if the underlying type is a List, which I personally doubt.

    Second, call the ToList() extension method on it:

    Buildings = (List)session.CreateCriteria(typeof(Building)).AddOrder(Order.Asc("buildingName")).List().ToList();
    

    I personally recommend that you do neither and use the IList instead.

提交回复
热议问题