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

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

  <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>

 

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

Department对象(接口)spa

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; }
    }
}

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

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));
        }
    }
}

 

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

提示:blog

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

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

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

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

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

相关文章
相关标签/搜索