单向父子关联不为null [英] Unidirectional parent-child association not null

查看:76
本文介绍了单向父子关联不为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于PurchaseOrder(父级)和PurchaseOrderLine(子级)模式的类结构,其中订单行仅通过保存父采购订单而保存到数据库中,并且也只能通过父采购订单来访问.

I have a class structure which is akin to a PurchaseOrder (parent) and PurchaseOrderLine (child) pattern, where the order lines will only be saved to the DB by saving the parent PurchaseOrder and will only ever be accessed via the parent too.

数据库已将PurchaseOrderLine.PurchaseOrder设置为不允许空值.

The DB has PurchaseOrderLine.PurchaseOrder set to not permit null values.

从网上搜索看来,不可能通过IList属性从PurchaseOrder进行单向关联,而不必在子级对其PurchaseOrder具有NOT NULL约束的行上具有指向该行的属性列.

It seems from searching through the web that it is not possible to have a uni-directional association from PurchaseOrder via an IList property without having to have a property on the line pointing back when the child has a NOT NULL constraint for its PurchaseOrder column.

真的是这样吗?似乎对于ORM来说,这是最基本的事情之一,我发现很难接受像NHibernate这样成熟的产品无法处理这种基本情况.

Is this really the case? It seems like one of the most basic things one would want to do with an ORM, I find it difficult to accept that a product as mature as NHibernate cannot handle such a basic scenario.

推荐答案

现在可以使用Not.KeyNullable()在NH3中实现

This can now be achieved in NH3 using the Not.KeyNullable()

        this.HasMany(x => x.Actions)
            .Access.BackingField()
            .KeyColumn("[Application]")
            .Not.KeyNullable()
            .Cascade.AllDeleteOrphan();

这篇关于单向父子关联不为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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