一、在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設爲啓動項目。 |