这是我的订单和 orderItem 类:public class Order : AggregateRootBase<OrderId>{ public string CustomerName { get; private set; } public IList<OrderItem> Items { get; set; } public DateTime RegisterDatetime { get; private set; }}public class OrderItem : ValueObjectBase{ public long Id { get; private set; } public long OrderId { get; set; } public long Number { get; private set; } public long Goods { get; private set; } public double UnitPrice { get; private set; }}我使用 nhibernate 作为我的 orm。在映射此代码时,我希望订单位于 Orders 表中,而 orderItem 将存储在名为 OrderItems 的不同表中。这是我的映射:public class OrderMapping : ClassMapping<Order>{ public OrderMapping() { Table("Orders"); Lazy(false); ComponentAsId(a => a.EntityId, a => { a.Property(x => x.DbId, x => x.Column("Id")); }); Property(a=>a.CustomerName); Property(a => a.RegisterDatetime); Bag(a => a.Items, mapper => { mapper.Inverse(true); mapper.Cascade(Cascade.None); mapper.Table("OrderItems"); mapper.Key(k => k.Column(columnMapper => columnMapper.Name("OrderId"))); }, relation => { relation.OneToMany(); }); }}public class OrderItemMapping : ClassMapping<OrderItem>{ public OrderItemMapping() { Lazy(false); Id(a => a.Id); Table("OrderItems"); Property(a => a.OrderId); Property(a => a.Number); Property(a => a.Goods); Property(a => a.UnitPrice); } }我也在数据库中创建了表,但是当我插入带有 3 个 orderItems 的订单时,它会插入订单但不插入 orderitems 感谢您的帮助
2 回答
- 2 回答
- 0 关注
- 179 浏览
添加回答
举报
0/150
提交
取消