How to: Create a Business Model in the XPO Data Model Designer
How to: Create a Business Model in the XPO Data Model Designer
This topic provides step-by-step instructions on how to use the XPO Data Model Designer in XAF applications. We will create a simple business model consisting of two objects - Employee and Task. These objects will be linked with a one-to-many relationship. Then you will add XAF-specific attributes in code, and the application will be ready to use.
- The XPO Data Model Designer requires Visual Studio 2010 (or later).
 - This designer can also be used to generate a data model for a legacy database (see How to: Generate XPO Business Classes for Existing Data Tables).
 
If you prefer to watch a video rather than walk through these step-by-step instructions, you can find the corresponding tutorial on the DevExpress YouTube Channel: XAF: Start from Building a Data Model using the XPO Data Model Designer.
 Create an XPO Data Model
Create a new XAF solution using the DevExpress v16.1 XAF Solution Wizard template.
Right-click the BusinessObjects folder located in the module project and choose Add | New Item. In the invokedAdd New Item dialog, select the DXperience ORM Data Model Wizard template located in the DevExpresscategory. Set the new item's name to MySolutionDataModel.xpo and click Add. You will see that theMySolutionDataModel.xpo item is added, and the wizard dialog is invoked.
In the invoked dialog, select Do not connect to a database and click Next, to skip the creation of a database connection using the XPO Data Model Wizard. The database connection is managed by XAF in your solution.

As a result, an empty data model will be shown in the designer.

 Design the Employee Object
To add a new business class, drag the XpObject item from the toolbox to the designer's surface.

Focus the newly added object. In the Properties window, set the object's Name to Employee.

To add a new persistent property, drag the Field item from the Toolbox to the Employee object.

Focus the newly added field. In the Properties window, set the field's Name to FirstName.

Note that the Column Type is String by default.
Repeat the two previous steps to add the LastName property.

Now add a field of a type other than string. Add the Birthday field, and set its Column Type to DateTime.

Next, you will see how to add a calculated field. Drag the Persistent Alias item from the Toolbox to the Employeeobject.

Focus the newly added persistent alias. In the Properties window, set Name to Full Name. Then, click the ellipsis button located to the right of the Expression setting. In the invoked Expression editor dialog, specify the[FirstName] + ' ' + [LastName] expression and click OK.

You can inherit the Employee class from the DevExpress.Persistent.BaseImpl.Person class, instead of creating it from scratch. The XPO Data Model Designer supports the use of persistent classes from external assemblies as base classes and property types. To add business classes from the Business Class Library (or your own class library), do the following.
- Right-click the free space on the design surface. In the invoked context menu, choose Add Assembly.
 - Select the assembly that contains business classes and click Open. You can choose the DevExpress.Persistent.BaseImpl.v16.1.dllassembly that ships with XAF, located in the %PROGRAMFILES(x86)%\DevExpress 16.1\Components\Bin\Framework path, or your custom assembly.
 - In the Select Types dialog, choose the persistent classes to import from the assembly and click OK.
 
These actions will import classes in read-only mode. Only persistent fields are displayed for these classes, and reference property types correspond to the underlying database types. However, you will be able to use the added classes as ancestors, and inherit new persistent classes from them in the Designer. To specify inheritance, select the Inheritance item in the Toolbox and draw a line from a descendant to a base class. Additionally, you will be able to use these classes as property types.
 Design the Task Object
To add another business class, drag the XpObject item from the toolbox to the designer's surface. Focus the newly added object. In the Properties window, set the object's Name to Task.

Add the Subject and Description persistent properties of the string type using the approach described in theDesign the Employee Object section.

Next, see how to apply attributes to persistent properties. Focus the Description field. In the Properties window, expand the DBType category, and set Size to Unlimited.

As a result, the SizeAttribute will be applied to the Description property in the underlying code. The attribute's parameter will be set to SizeAttribute.Unlimited.
 Add a One-to-Many Association
Add the AssignedTo persistent property of the Employee type to the Task class. This property will represent the "one" part of the one-to-many association.

In the Toolbox, focus the Association Object item. Draw a line from Employee to Task, to create the association.

Alternatively, you can use the XpObject's title bar context menu to create an association. For details, refer to the Associationsection of the Data Model Designer topic.
- Save the changes and close the designer.
 
 Add XAF-Specific Attributes in Code
In the Solution Explorer, expand the BusinessObjects\MySolutionDataModelCode folder. This folder contains the code generated by the designer. Open the Employee.cs (Employee.vb) file. Decorate the Employee class with theDefaultClassOptionsAttribute and ImageNameAttribute attributes to the Employee object. As a result, theEmployee object will be added to the Navigation System, and an icon from the built-in library will be associated with this object.
C#VBusing DevExpress.Persistent.Base;
// ...
[DefaultClassOptions, ImageName("BO_Employee")]
public partial class Employee {
public Employee(Session session) : base(session) { }
public Employee() : base(Session.DefaultSession) { }
public override void AfterConstruction() { base.AfterConstruction(); }
}Open the Task.cs (Task.vb) file. Decorate the Task class with the DefaultClassOptions and ImageName attributes.
C#VBusing DevExpress.Persistent.Base;
// ...
[DefaultClassOptions, ImageName("BO_Task")]
public partial class Task {
public Task(Session session) : base(session) { }
public Task() : base(Session.DefaultSession) { }
public override void AfterConstruction() { base.AfterConstruction(); }
}
You can add more custom code to the auto-generated classes (e.g., add Action methods or override base class methods). Do not change the code located in files with the designer suffix - they contain designer-generated code, and should not be modified manually. The classes generated are declared as partial. Designed and custom class parts are located in different files.
 Run the Application
Now you can run the Windows Forms and ASP.NET applications to see the result. These applications are completely based on the business model specified in the XPO Data Model Designer.
Windows Forms

ASP.NET

How to: Create a Business Model in the XPO Data Model Designer的更多相关文章
- How to: Create a Business Model in the XPO Data Model Designer 如何:在 XPO 数据模型设计器中创建业务模型
		
This topic provides step-by-step instructions on how to use the XPO Data Model Designer in XAF appli ...
 - Create Entity Data Model
		
http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...
 - Entity Framework Tutorial Basics(5):Create Entity Data Model
		
Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...
 - How to: Use the Entity Framework Data Model Located in an External Assembly 如何:使用位于外部程序集中的EF数据模型
		
If you have a non-XAF application, and want to develop an XAF application that utilizes the same dat ...
 - Define the Data Model and Set the Initial Data 定义数据模型并设置初始数据
		
This topic describes how to define the business model and the business logic for WinForms and ASP.NE ...
 - HBase 数据模型(Data Model)
		
HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...
 - ExtJS笔记   Ext.data.Model
		
A Model represents some object that your application manages. For example, one might define a Model ...
 - [Angular 2] Adding a data model
		
Instead of add todo as a string, we create a data model: export class TodoModel{ constructor( public ...
 - 自定义 ASP.NET Identity Data Model with EF
		
One of the first issues you will likely encounter when getting started with ASP.NET Identity centers ...
 
随机推荐
- omitTermFreqAndPositions设置,词频FQ在打分中默认为1
			
compressed=true|false,是否使用gzip压缩(只有TextField和StrField可以压缩) compressThreshold=压缩阀值 multiValued=true|f ...
 - js的两种查询方式 LHS and RHS
			
为了进一步理解,我们需要多介绍一点编译器的术语.编译器在编译过程的第二步中生成了代码,引擎执行它时,会通过查找变量 a 来判断它是否已声明过.查找的过程由作用域进行协助,但是引擎执行怎样的查找,会影响 ...
 - SqlServer-truncate && delete && drop 的区别
			
有些人在删除表的所有记录的时候,喜欢这样来——不给DELETE 语句提供WHERE 子句,表中的所有记录都将被删除.但这种方法是不可取的,正确的应该使用 TRUNCATE TABLE tb_name ...
 - Luogu 4841 城市规划
			
BZOJ 3456 权限题 太菜了推不出式子 我们设$f(n)$表示$n$个点的无向连通图的数量,那么有 $$f(n) = 2^{\binom{n}{2}} - \sum_{i = 1}^{n - 1 ...
 - Luogu 3665 [USACO17OPEN]Switch Grass 切换牧草
			
BZOJ 4777 被权限了. 这道题的做法看上去不难,但是感觉自己yy不出来. 首先是两个结论: 1.答案一定是连接着两个异色点的一条边. 2.答案一定在最小生成树上. 感觉看到了之后都比较显然,自 ...
 - 2.一个简单的c++程序。
			
每个程序员的Hello World程序 //This is a small c++ program #include <iostream> int main() { std::cout & ...
 - 多线程协作  FileStream文件读写操作,读写冲突解决
			
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
 - 编写高质量代码改善C#程序的157个建议——建议35:使用default为泛型类型变量指定初始值
			
建议35:使用default为泛型类型变量指定初始值 有些算法,比如泛型集合List<T>的Find算法,所查找的对象可能会是值类型,也有可能是引用类型.在这种算法内部,我们常常会为这些值 ...
 - 【Head First Java 读书笔记】(二)类与对象
			
前篇当中,代码都放在main()里面,那根本不是面向对象的做法. 椅子大战(对象如何改变你的一生) 程序规格: 在图形接口画出四方形,圆形和三角形,当用户点选图形时,图形需要顺时针转360度并依据形状 ...
 - HackFifteen 移除背景以提升Activity启动速度
			
1.概要: 移除窗口默认背景是提升应用程序启动速度的一个简单技巧.判断是否需要移除背景的原则很简单:如果应用程序界面需要 占据窗口100%的控件,就需要将windowBackground属性设 ...