使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D.不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息。我们只做个简单 的客户信息来了解一下XAF好了。 新建项之后,可以看到如下代码界面:using System;using ...
使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D.
不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息。我们只做个简单 的客户信息来了解一下XAF好了。
新建项之后,可以看到如下代码界面:
using System;using System.Linq;using System.Text;using DevExpress.Xpo;using DevExpress.ExpressApp;using System.ComponentModel;using DevExpress.ExpressApp.DC;using DevExpress.Data.Filtering;using DevExpress.Persistent.Base;using System.Collections.Generic;using DevExpress.ExpressApp.Model;using DevExpress.Persistent.BaseImpl;using DevExpress.Persistent.Validation;namespace XCRMDemo.Module.BusinessObjects{ [DefaultClassOptions] //[ImageName("BO_Contact")] //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")] //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)] //[Persistent("DatabaseTableName")] // Specify more UI options using a declarative approach (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112701.aspx). public class 客户 : BaseObject { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx). public 客户(Session session) : base(session) { } public override void AfterConstruction() { base.AfterConstruction(); // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx). } //private get='_blank'>string _PersistentProperty; //[XafDisplayName("My display name"), ToolTip("My hint message")] //[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)] //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)] //public string PersistentProperty { // get { return _PersistentProperty; } // set { SetPropertyValue("PersistentProperty", ref _PersistentProperty, value); } //} //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)] //public void ActionMethod() { // // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx). // this.PersistentProperty = "Paid"; //} }}
Oid是在BaseObject中定义的,所以客户类会自动建立这个字段。OptimisticLockField:是XAF为了解决并发冲突而建立的字段。GCRecord:继承自BaseObject的类在删除记录时只是逻辑删除,即只是将GCRecord中记录一个值,而没有删除的记录则为Null.
39 private string _姓名; 40 41 public string 姓名 42 { 43 get { return _姓名; } 44 set { SetPropertyValue("姓名", ref _姓名, value); } 45 }
这个属性和以往开发中的方法没有什么大的不同,仅是在set部分调用了SetPropertyValue方法,xpo为我们提供了一系列基类,SetPropertyValue是多数类中都有的,它的功能是可以在有值被设置时,需要得到属性变化时可以及时的得到通知。可以看到,字符串类型的姓名,在界面上最终显示成了一个文本框,XAF中内置了很多这样的控件,与类型做出了对应关系,当我们使用对应的类型时,就会自动使用对应的控件,这里的控件被叫做编辑器(PropertyEditor)。接下来,有禁用属性:
private bool _禁用; public bool 禁用 { get { return _禁用; } set { SetPropertyValue("禁用", ref _禁用, value); } }
除了自动建立的3个字段外,别的字段都是与代码有对应关系的映射了,xpo默认支持以下几种类型的映射:
C# System data type | Advantage | Asa | Ase | DB2 | Firebird | MySQL | MS Access | MSSQL | MSSQL CE | Oracle | Pervasive SQL | Postgre SQL | VistaDB |
---|
System.Boolean | logical | bit | bit | char(1) | char(1) | bit | bit | bit | bit | number(1,0) | bit | bool | Bit |
System.Byte | short | tinyint | tinyint | smallint | numeric(3,0) | tinyint unsigned | byte | tinyint | tinyint | number(3,0) | smallint | smallint | Int |
System.SByte | short | numeric(3,0) | numeric(3,0) | numeric(3,0) | numeric(3,0) | tinyint | short | numeric(3,0) | numeric(3,0) | number(3,0) | numeric(3,0) | smallint | SmallInt |
System.Char | char(1) | char(1) | nchar(1) | char(1) | char CHARACTER SET UNICODE_FSS | char | char(1) | nchar(1) | nchar(1) | nchar | char(1) | char(1) | NChar |
System.Decimal | money | money | money | decimal(28,4) | decimal(18,4) | double | currency | money | numeric(19,4) | number(19,5) | decimal(20,4) | decimal(28,8) | Decimal |
System.Double | double | double precision | double precision | double precision | double precision | double | double | double precision | float | double precision | double | double precision | Float |
System.Single | double | float | float | float | float | real | single | float | real | float | real | real | Float |
System.Int16 | short | smallint | smallint | smallint | smallint | smallint | short | smallint | smallint | number(5,0) | smallint | smallint | SmallInt |
System.UInt16 | integer | numeric(5,0) | numeric(5,0) | numeric(5,0) | numeric(5,0) | smallint unsigned | int | numeric(5,0) | numeric(5,0) | number(5,0) | numeric(5,0) | numeric(5,0) | Int |
System.Int32 | integer | int | numeric(10,0) | int | integer | int | int | int | int | int | integer | int | Int |
System.UInt32 | money | numeric(10,0) | numeric(10,0) | numeric(10,0) | numeric(10,0) | int unsigned | decimal(10,0) | numeric(10,0) | numeric(10,0) | numeric(10,0) | numeric(10,0) | numeric(10,0) | BigInt |
System.Int64 | money | bigint | numeric(20,0) | bigint | bigint | bigint | decimal(20,0) | bigint | bigint | number(20,0) | bigint | bigint | BigInt |
System.UInt64 | money | numeric(20,0) | numeric(20,0) | numeric(20,0) | numeric(18,0) | bigint unsigned | decimal(20,0) | numeric(20,0) | numeric(20,0) | number(20,0) | numeric(20,0) | numeric(20,0) | BigInt |
System.Guid | char(36) | UNIQUEIDENTIFIERSTR | char(36) | char(36) | char(36) | char(38) | guid | uniqueidentifier | uniqueidentifier | char(36) | char(36) | char(36) | UniqueIdentifier |
System.Enum | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type | underlying type |
System.String | char | varchar | nvarchar | varchar | char varying | varchar | varchar | nvarchar | nvarchar | nvarchar2 | varchar | varchar | NVarChar |
System.DateTime | timestamp | datetime | datetime | timestamp | timestamp | datetime | datetime | datetime | datetime | date | timestamp | timestamp | DateTime |
System.TimeSpan | double | double precision | double precision | double precision | double precision | double | double | double precision | float | double precision | double | double precision | Float |
System.Byte[] | blob | image | image | blob | blob | LONGBLOB | longbinary | image, in SQL Server[Size(SizeAttribute.Unlimited), VisibleInListView(true)] [ImageEditor(ListViewImageEditorMode = ImageEditorMode.PictureEdit, DetailViewImageEditorMode = ImageEditorMode.PictureEdit, ListViewImageEditorCustomHeight = 40)] public byte[] 照片 { get { return GetPropertyValue<byte[]>("照片"); } set { SetPropertyValue<byte[]>("照片", value); } } 因为本节主要介绍业务对象的创建方法,不扩展讨论Attribute的用法,后续章节详细描述。下节介绍几种常见的关系型数据库节构在ORM中的实现方法。QQ:4603528 QQ群:50185791
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:XAF应用开发教程(二)业务对象模型之简单类型属性
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。
|