NHibernate IList to List

前端 未结 3 1699
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  被撕碎了的回忆
    2021-01-03 11:57

    That's not how NHibernate works. You don't get to tell it what the concrete types of your domain model objects are. You only get to tell it what the base types and interfaces are. Then it gets to choose how to implement the domain types efficiently.

    For example, NHibernate uses its own internal implementation of IList that knows how to do lazy loading.

    Moreover, NHibernate uses its own internal implementation of Building from your domain model. It is not necessarily the case that all the Building objects you will be using with NHibernate will have, as their concrete type, Building. It is only true that they will be Buildings, whether Building is the concrete type of your object, or whether it is the base type of the concrete type of your object.

    But this is the right thing to do, since you are supposed to be using interfaces and base types instead of concrete types anyway. NHibernate helps you use all the right approaches to programming.

    Now, why do you need a List per se? Why will IList not suffice?

提交回复
热议问题