学习008-02-01-03 Extend the Data Model(扩展数据模型)

Extend the Data Model(扩展数据模型)

This lesson explains how to extend your entity class with different properties.
本课介绍如何使用不同的属性扩展实体类。

During this lesson, you will do the following:
在本课中,您将执行以下操作:

  • Add properties of different types to the entity class.(向实体类添加不同类型的属性。)
  • See how the field editor type depends on the property’s value type.(了解字段编辑器类型如何依赖于属性的值类型。)

1.Add the following properties to the Employee class:
将以下属性添加到员工类:

C#

using System.ComponentModel.DataAnnotations.Schema;

namespace MySolution.Module.BusinessObjects;

[DefaultClassOptions]
public class Employee : BaseObject
{
    //...

    public virtual DateTime? Birthday { get; set; }

    //Use this attribute to hide or show the editor of this property in the UI.
    [Browsable(false)]
    public virtual int TitleOfCourtesy_Int { get; set; }

    //Use this attribute to exclude the property from database mapping.
    [NotMapped]
    public virtual TitleOfCourtesy TitleOfCourtesy { get; set; }

}

    public enum TitleOfCourtesy
{
    Dr,
    Miss,
    Mr,
    Mrs,
    Ms
}

The NotMapped attribute requires the System.ComponentModel.DataAnnotations.Schema using directive.
NotMap属性需要System.ComponentModel.DataAnnotations.Schema use指令。

2.Add a migration and update the database. See the following section for details: Use a DBMS: Setup Migrations.
添加迁移并更新数据库。有关详细信息,请参阅以下部分:使用DBMS:设置迁移。

3.Run the application and invoke the Employee object’s Detail View. The application displays a date picker for the DateTime type of values (see Birthday) and a combo box for the enumeration fields (see Title Of Courtesy):
运行应用程序并调用员工对象的详细信息视图。应用程序显示DateTime类型值的日期选择器(请参阅生日)和枚举字段的组合框(请参阅标题礼貌):

ASP.NET Core Blazor
在这里插入图片描述

Windows Forms
在这里插入图片描述

4.Extend the Employee class further with the following properties. Note the attributes that decorate these properties. Use hyperlinks to learn more about the attributes if their meanings are not immediately clear.
使用以下属性进一步扩展员工类。注意装饰这些属性的属性。如果属性的含义不清楚,请使用超链接了解有关属性的更多信息。

C#

using DevExpress.Persistent.Validation;
using System.ComponentModel.DataAnnotations;

namespace MySolution.Module.BusinessObjects;

[DefaultClassOptions]
//Use this attribute to specify the caption format for the objects of the entity class.
[ObjectCaptionFormat("{0:FullName}")]   
[DefaultProperty(nameof(FullName))]
public class Employee : BaseObject
{
    //...

    [SearchMemberOptions(SearchMemberMode.Exclude)]
    public String FullName
    {
        get { return ObjectFormatter.Format(FullNameFormat, this, EmptyEntriesMode.RemoveDelimiterWhenEntryIsEmpty); }
    }

    [EditorBrowsable(EditorBrowsableState.Never)]
    public String DisplayName
    {
        get { return FullName; }
    }

    public static String FullNameFormat = "{FirstName} {MiddleName} {LastName}";

    //Use this attribute to specify the maximum number of characters that users can type in the editor of this property.
    [FieldSize(255)]
    public virtual String Email { get; set; }

    //Use this attribute to define a pattern that the property value must match.
    [RuleRegularExpression(@"(((http|https)\://)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*)|([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})", CustomMessageTemplate = @"Invalid ""Web Page Address"".")]
    public virtual string WebPageAddress { get; set; }

    //Use this attribute to specify the maximum string length allowed for this data field.
    [StringLength(4096)]
    public virtual string Notes { get; set; }

 }

5.Add a migration and update the database. See the following section for details: Use a DBMS: Setup Migrations.
添加迁移并更新数据库。有关详细信息,请参阅以下部分:使用DBMS:设置迁移。

6.Run the application and invoke the Employee object’s Detail View:
运行应用程序并调用员工对象的详细信息视图:

ASP.NET Core Blazor
在这里插入图片描述

Windows Forms
在这里插入图片描述

As you can see, XAF places the Notes editor outside of the group box that contains smaller editors. This is the framework’s default behavior for user-resizable editors. If you want to change the layout, use the steps described in the following lesson: Display a Nested Property Editor in a Detail View.
如您所见,XAF将Notes编辑器放在包含较小编辑器的分组框之外。这是框架对用户可调整大小的编辑器的默认行为。如果要更改布局,请使用以下课程中描述的步骤:在详细信息视图中显示嵌套属性编辑器。

Next Lesson(下一课)

Supply Initial Data
提供初始数据

  • 25
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值