NHibernate IList列出 [英] NHibernate IList to List

查看:75
本文介绍了NHibernate IList列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试返回建筑领域的集合.

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

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

我正在使用NHibernate以及该房间的映射

I am using NHibernate and this mapping for the rooms

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

我这样叫数据库;

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

问题是我不希望_rooms集合成为IList,但我需要将其成为List. ,NHibernate要求我使用接口进行收集. 任何想法如何做到这一点.我是.Net的新手,并认为放弃NHibernate可能是前进的道路.我只需要将收藏集键入为列表即可继续. 任何帮助表示赞赏.

The problem is I don't want the _rooms collection to be an IList but I need it to be a List. Alas, NHibernate requires that I use an Interface for collections. Any idea how to do this. I am new to .Net and thinking that maybe dropping NHibernate might be the way forward. I just need to get the collection typed as an List so I can move on. Any help much appreciated.

推荐答案

那不是NHibernate的工作原理.您无需告诉它域模型对象的具体类型是什么.您只能告诉它基本类型和接口是什么.然后可以选择如何有效地实现域类型.

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.

例如,NHibernate使用其自己的IList<T>内部实现,该实现知道如何进行延迟加载.

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

此外,NHibernate使用您自己的域模型中的Building内部实现.不一定要与NHibernate一起使用的所有Building对象都具有Building作为其具体类型.无论Building是对象的具体类型,还是对象的具体类型的基本类型,它们都是Building.

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.

但这是正确的事情,因为应该使用接口和基本类型,而不是具体类型. NHibernate可帮助您使用所有正确的编程方法.

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.

现在,为什么您本身需要一个List<Building>?为什么IList<Building>不够用?

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

这篇关于NHibernate IList列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆