DevExpress Xaf入门——关于一对多关系的配置(DC模式)

1、在VS2012中通过新建XAF解决方案Solution2,并在Solution2.Web项目中的配置文件Web.config中配置连接字符串;

  <connectionStrings>
    <add name="EasyTestConnectionString" connectionString="Integrated Security=SSPI;Pooling=false;Data Source=.\SQLEXPRESS;Initial Catalog=Solution2EasyTest" />
    <add name="ConnectionString" connectionString="Data Source=GUANBAOPC\SQLEXPRESS;Initial Catalog=Solution2DB;Persist Security Info=true;User ID=sa;Password=123" />
  </connectionStrings>

 

2、在解决方案Solution2中对应的项目Solution2.Module的文件夹BusinessObjects中新建Xaf Domain Component对象Department、Employee。

Department对象(接口)

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

namespace Solution2.Module.BusinessObjects
{
    [DomainComponent]
    [DefaultClassOptions]
    [XafDisplayName("部门信息")]
    public interface Department
    {
        [XafDisplayName("部门名称")]
        string DepartmentName { get; set; }

        [XafDisplayName("部门编号")]
        string DepartmentCode { get; set; }

        [XafDisplayName("联系电话")]
        string ContactNumber { get; set; }

        [XafDisplayName("部门员工")]
        IList<Employee> DepartmentEmployees { get; }
    }
}

Employee对象(接口)

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

namespace Solution2.Module.BusinessObjects
{
    [DomainComponent]
    [DefaultClassOptions]
    [XafDisplayName("员工信息")]
    public interface Employee
    {
        [XafDisplayName("员工姓名")]
        string EmployeeName { get; set; }

        [XafDisplayName("工号")]
        string JobNumber { get; set; }

        [XafDisplayName("部门")]
        Department Department { get; set; }
    }
}

3、右键Solution2.Module中的Module.cs文件,点击查看代码,在打开的Module.cs文档中注册Employee与Department对象。

using System;
using System.Text;
using System.Linq;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.DC;
using System.Collections.Generic;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Updating;
using DevExpress.ExpressApp.Model.Core;
using DevExpress.ExpressApp.Model.DomainLogics;
using DevExpress.ExpressApp.Model.NodeGenerators;
using Solution2.Module.BusinessObjects;

namespace Solution2.Module
{
    public sealed partial class Solution2Module : ModuleBase
    {
        public Solution2Module()
        {
            InitializeComponent();
        }
        public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB)
        {
            ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
            return new ModuleUpdater[] { updater };
        }
        public override void Setup(XafApplication application)
        {
            base.Setup(application);
            XafTypesInfo.Instance.RegisterEntity("Employee", typeof(Employee));
           XafTypesInfo.Instance.RegisterEntity("Department", typeof(Department));
        }
    }
}

 

4、将Solution2.Web设为启动项目,并使用调试模式运行解决方案。

提示:

1、部门对象(Deparment)中部门员工属性(DepartmentEmployees)不能设置set方法;

2、员工对象(Employee)中部门员工属性(DepartmentEmployees)类型IList<Employee>不能配置为List<Employee>;

3、员工对象(Employee)中必须存在部门属性(Department)且必须带有get和set方法。

4、第一次运行解决方案会弹出错误提示,重新运行解决方案后员工与部门的一对多关系的界面就出来了。

5、必须将Solution2.Web设为启动项目。

 

 

转载于:https://www.cnblogs.com/xuguanbao/p/3571901.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值