NHibernate IList to List

Hi, I am trying to return a collection of a construction domain.

private long _id;
private string _buildingName;
private IList<BasicRoom> _rooms;

I am using NHibernate and this mapping is for rooms

<bag name="rooms" table="tb_rooms" lazy="false">
<key column="buildingID"/>
<one-to-many class="Room"/>
</bag>

And I call db as follows:

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

The problem is that I don’t want the _rooms collection to be an IList, but I need it to be a list. Alas, NHibernate requires me to use the collection interface. Any ideas how to do this. I am new to .Net and I think that maybe dropping NHibernate could be a further step forward. I just need to get a collection typed as a list so that I can move on. Any help is greatly appreciated.

+3
source share
3 answers

, NHibernate. , . , . .

, NHibernate IList<T>, , .

, NHibernate Building . , Building, NHibernate, , , Building. , Building s, , Building .

, . NHibernate .

, List<Building> ? IList<Building> ?

+12

List, , , IList?

, .

IList<Building> List<Building>. , - List<Building>, .

-, ToList() :

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

IList.

+5

How to use a constructor List<T>that accepts IEnumerable<T>? Then you can use:

Buildings = new List<Building>(session.CreateCriteria(typeof(Building)).AddOrder(Order.Asc("buildingName")).List<Building>());
+2
source

Source: https://habr.com/ru/post/1702452/


All Articles