首页 > 其他 > 详细

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

时间:2014-02-28 10:57:28      阅读:489      评论:0      收藏:0      [点我收藏+]

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对象(接口)

bubuko.com,布布扣
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; }
    }
}
bubuko.com,布布扣

Employee对象(接口)

bubuko.com,布布扣
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; }
    }
}
bubuko.com,布布扣

3、打开项目Solution2.Module中的Module.cs下面的Solution2Module文件,注册Employee与Department对象。

bubuko.com,布布扣
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));
        }
    }
}
bubuko.com,布布扣

 

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

bubuko.com,布布扣

提示:

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

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

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

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

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

 

DevExpress Xaf入门——关于一对多关系的配置(DC模式),布布扣,bubuko.com

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

原文:http://www.cnblogs.com/xuguanbao/p/3571901.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!