Xaf BO建模一对多(One to Many)关系

这篇博客探讨了在使用DevExpress的XAF框架中,如何处理业主、制造任务单和经营合同之间的多对一关系。业主可以有多个制造任务和经营合同,而每个制造任务和经营合同都对应一个特定的业主。通过代码示例展示了对象关系映射和数据模型的设计,强调了在业务逻辑中维护这种关系的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在工程项目中,一个业主给工厂多个制造合同,在生产制造环节就形成了一个业主多个制造任务同时进行的状态。

直接上干货。

业主库BO:

using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace MyMOM.Module.BusinessObjects
{
    [DefaultClassOptions]
    //[ImageName("BO_Contact")]
    //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
    //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
    //[Persistent("DatabaseTableName")]
    // Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
    public class PF_CRM_业主库 : BaseObject
    { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
        public PF_CRM_业主库(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).
        }
        //private string _PersistentProperty;
        //[XafDisplayName("My display name"), ToolTip("My hint message")]
        //[ModelDefault("EditMask", "(000) - 00"), Index(0), VisibleInListView(false)]
        //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
        //public string PersistentProperty {
        //    get { return _PersistentProperty; }
        //    set { SetPropertyValue(nameof(PersistentProperty), ref _PersistentProperty, value); }
        //}
        //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure ? ", ImageName = "Attention", AutoCommit = true)]
        //public void ActionMethod() {
        //    // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx).
        //    this.PersistentProperty = "Paid";
        //}
        string f名称;
        [Size(255)]
        public string 名称
        {
            get { return f名称; }
            set { SetPropertyValue<string>(nameof(名称), ref f名称, value); }
        }
        //MD_PUB_公司库 f公司信息;
        //[Association(@"PF_CRM_业主库ReferencesMD_PUB_公司库")]
        //public MD_PUB_公司库 公司信息
        //{
        //    get { return f公司信息; }
        //    set { SetPropertyValue<MD_PUB_公司库>(nameof(公司信息), ref f公司信息, value); }
        //}
        string f备注;
        [Size(512)]
        public string 备注
        {
            get { return f备注; }
            set { SetPropertyValue<string>(nameof(备注), ref f备注, value); }
        }
        //[Association(@"PF_CRM_经营合同ReferencesPF_CRM_业主库")]
        //public XPCollection<PF_CRM_经营合同> PF_CRM_经营合同s { get { return GetCollection<PF_CRM_经营合同>(nameof(PF_CRM_经营合同s)); } }
        //[Association(@"PF_CRM_业主信誉ReferencesPF_CRM_业主库")]
        //public XPCollection<PF_CRM_业主信誉> PF_CRM_业主信誉s { get { return GetCollection<PF_CRM_业主信誉>(nameof(PF_CRM_业主信誉s)); } }
        [Association(@"PF_CRM_制造任务单ReferencesPF_CRM_业主库")]
        public XPCollection<PF_CRM_制造任务单> PF_CRM_制造任务单s { get { return GetCollection<PF_CRM_制造任务单>(nameof(PF_CRM_制造任务单s)); } }
        //[Association(@"PF_CRM_制造项目ReferencesPF_CRM_业主库")]
        //public XPCollection<PF_CRM_制造项目> PF_CRM_制造项目s { get { return GetCollection<PF_CRM_制造项目>(nameof(PF_CRM_制造项目s)); } }
    }

}

制造任务单BO:

using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace MyMOM.Module.BusinessObjects
{
    [DefaultClassOptions]
    //[ImageName("BO_Contact")]
    //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
    //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
    //[Persistent("DatabaseTableName")]
    // Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
    public class PF_CRM_制造任务单 : BaseObject
    { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
        public PF_CRM_制造任务单(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).
        }
        //private string _PersistentProperty;
        //[XafDisplayName("My display name"), ToolTip("My hint message")]
        //[ModelDefault("EditMask", "(000) - 00"), Index(0), VisibleInListView(false)]
        //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
        //public string PersistentProperty {
        //    get { return _PersistentProperty; }
        //    set { SetPropertyValue(nameof(PersistentProperty), ref _PersistentProperty, value); }
        //}
        //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure ? ", ImageName = "Attention", AutoCommit = true)]
        //public void ActionMethod() {
        //    // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx).
        //    this.PersistentProperty = "Paid";
        //}
        string f名称;
        [Size(255)]
        public string 名称
        {
            get { return f名称; }
            set { SetPropertyValue<string>(nameof(名称), ref f名称, value); }
        }
        string f编码;
        [Size(64)]
        public string 编码
        {
            get { return f编码; }
            set { SetPropertyValue<string>(nameof(编码), ref f编码, value); }
        }
        PF_HR_公司员工 f编制人;
        [Association(@"PF_CRM_制造任务单ReferencesPF_HR_公司员工")]
        public PF_HR_公司员工 编制人
        {
            get { return f编制人; }
            set { SetPropertyValue<PF_HR_公司员工>(nameof(编制人), ref f编制人, value); }
        }
        DateTime f编制日期;
        public DateTime 编制日期
        {
            get { return f编制日期; }
            set { SetPropertyValue<DateTime>(nameof(编制日期), ref f编制日期, value); }
        }
        PF_CRM_业主库 f业主;
        [Association(@"PF_CRM_制造任务单ReferencesPF_CRM_业主库")]
        public PF_CRM_业主库 业主
        {
            get { return f业主; }
            set { SetPropertyValue<PF_CRM_业主库>(nameof(业主), ref f业主, value); }
        }
        int f版本;
        public int 版本
        {
            get { return f版本; }
            set { SetPropertyValue<int>(nameof(版本), ref f版本, value); }
        }
        //PF_CRM_经营合同 f经营合同;
        //[Association(@"PF_CRM_制造任务单ReferencesPF_CRM_经营合同")]
        //public PF_CRM_经营合同 经营合同
        //{
        //    get { return f经营合同; }
        //    set { SetPropertyValue<PF_CRM_经营合同>(nameof(经营合同), ref f经营合同, value); }
        //}
        string f备注;
        [Size(255)]
        public string 备注
        {
            get { return f备注; }
            set { SetPropertyValue<string>(nameof(备注), ref f备注, value); }
        }
    }

}

同样的,业主和经营合同也是一对多的关系。

经营合同与制造任务也是一对多的关系。就是一个签订了一个经营合同,根据业务进度安排或工厂自身的生产制造状况安排一个或多个制造任务下达给工厂或车间。

鉴于XAF的整体架构,不建议在BO的名称和属性名称中使用中文。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_16215957

如果有帮助一杯咖啡奶茶均可

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值