一对多的nHibernate空列表值 [英] nHibernate Null List Values on One-To-Many

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

问题描述

我有一个包含许多OrderItems的Order映射.当我仅对订单进行保存时,映射将Order和OrderItems正确地保存到数据库中,但是当我重新加载该订单时,该订单包含的OrderItems列表将填充为空值(对于所有其他订单项,表格),直到到达具有订单外键的OrderItem为止.因此,空订单商品的总数是OrderItems表的行数(不含与该订单相关的实际订单商品).这是我的映射:

I have an Order mapping with many OrderItems. The mapping correctly saves both the Order and OrderItems to the database when I do a save on just the Order, but when I reload that order, the List of OrderItems that the order contains is filled with null values (for all the othe order items in the table) until it reaches the OrderItem that has the Order's foreign key. So the total count of null order items is the row count of the OrderItems table, (sans the actual order items that are related to the Order). Here's my mappings:

订单:

<list name="OrderItems" table="OrderItems" cascade="all" inverse="true" >
  <key column="OrderID"/>
  <index column="OrderItemID" />
  <one-to-many class="OrderItem" not-found="ignore" />
</list>

OrderItem:

OrderItem:

<many-to-one name="Order" class="Order" column="OrderID" not-null="true" />

这是Order的类实现:

Here's the Order's class implementation:

public class Order : {
    private IList<OrderItem> orderItems = new List<OrderItem>();

我读到nHibernate不支持列表,因为它是关系的许多部分,但是保存可以正常工作,而不是加载.我是否必须将所有内容都转换为Sets才能起作用?

I read that nHibernate doesn't support Lists as the many part of a relationship, but the save works correctly, just not the load. Do I have to convert everything over to Sets in order for this to work?

推荐答案

只是记得我的脑袋有问题

Just of the top of my head I remember having problems with

<list> 

并诉诸

<bag> 

而不是映射到.NET IList接口.不确定是否能解决您的问题.

instead to map to the .NET IList interface. Not sure if that will solve your problem.

通过启用登录console.out(

What may be helpful is to look at how the actual SQL that is hitting the database is different from what you expect by enabling logging to console.out (see this blog)

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

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