如何在XAF中的两个业务对象之间的一对多关系中强制执行输入

时间:2017-10-13 11:55:42

标签: vb.net xaf

我有一个Bill和PR课程,它们之间有一对多的关系(一个Bill到多个PR),如何根据Bill类中的Amount属性强制输入PR类? 只有当 Amount> = FIXED_AMOUNT 然后强制输入PR细节时,否则不要这样做。

<DefaultClassOptions()> _
Public Class Bill Inherits BaseObject
Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub 
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Private _Amount As Decimal
    Public Property Amount() As Decimal
        Get
         Return _Amount
        End Get
        Set(ByVal value As Decimal)
            _Amount = value
        End Set
    End Property

    Private _PR As PR
    <Association("PR-Bill")>
    Public Property PR As PR
        Get
            Return _PR
        End Get
        Set(ByVal value As PR)
            SetPropertyValue("PR", _PR, value)
        End Set
    End Property    
End Class

<DefaultClassOptions()> _
Public Class PR Inherits BaseObject
Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
     Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        End Sub
        Private _Name As String
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    <Association("PR-Bill")>
    Public ReadOnly Property Bill() As XPCollection(Of Bill)
        Get
            Return GetCollection(Of Bill)("Bill")
        End Get
    End Property    
End Class

1 个答案:

答案 0 :(得分:0)

使用DevExpress.Persistent.Validation

类似

[NotMapped, Browsable(false),
RuleFromBoolProperty("NeedsInputRule", DefaultContexts.Save,"You need to input PR ", UsedProperties = "Amount")]

public bool NeedsInput => Amount >= Fixed_Amount;