gpt4 book ai didi

c# - 实例化一个休眠集合

转载 作者:行者123 更新时间:2023-11-30 19:49:19 24 4
gpt4 key购买 nike

在我的订单实体中,我在 orderItems 上得到了一个空引用。这发生在首次创建订单时。我希望能够添加类似的内容

order.OrderItems = new Iesi.Collections.Set<OrderItem>();

错误是“无法在此处访问 protected 构造函数“Set”

    public class Order
{
public virtual int Id { get; set; }
public virtual ISet<OrderItem> OrderItems { get; set; }

public virtual void AddOrderItem(OrderItem item)
{
item.Order = this;
// OrderItems below is null
OrderItems.Add(item);
}

}


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="EStore.Domain"
namespace="EStore.Domain.Model">

<class name="Order" table="Orders">
<id name="Id" type="Int32" column="Id" unsaved-value="0">
<generator class="identity"/>
</id>

<property name="UserName" column="UserName"/>
<set name="OrderItems" table="OrderItems" generic="true" cascade="all-delete-orphan" inverse="true" >
<key column="OrderId" not-null="true" />
<one-to-many class="EStore.Domain.Model.OrderItem, EStore.Domain" />
</set>

</class>
</hibernate-mapping>

最佳答案

在构造函数中将 OrderItems 设置为新的 List

public Order() {
OrderItems = new List<OrderItem>();
}

关于c# - 实例化一个休眠集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4195731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com