In this lesson, you will learn how to set the default value for a particular property of a business class. For this purpose, the Priority property will be added to the DemoTask class created in the Set a Many-to-Many Relationship (EF) lesson. To initialize it, assign a value to this property in the constructor.

在本课中,您将学习如何为 Business 类的特定属性设置默认值。为此,优先级属性将添加到在"设置多对多关系 (EF)"一课中创建的 DemoTask 类中。要初始化它,请为构造函数中的此属性赋值。

Note

Before proceeding, take a moment to review the following lessons:

  • Inherit from the Business Class Library Class (EF)
  • Set a Many-to-Many Relationship (EF)
  • Add the Priority property to the DemoTask class and declare the Priority enumeration, as shown below:

  • 注意

    在继续之前,请花点时间复习以下课程:

  • 从业务类库类 (EF) 继承

  • 设置多对多关系 (EF)

  • 将"优先级"属性添加到 DemoTask 类并声明优先级枚举,如下所示:

    namespace MySolution.Module.BusinessObjects {
    //...
    public class DemoTask : Task {
    //...
    public Priority Priority { get; set; }
    } public enum Priority {
    Low = ,
    Normal = ,
    High =
    }
    }
  • In the Module.cs (Module.vb) file, register the Priority enumeration type in the constructor of your ModuleBase descendant using the EnumProcessingHelper.RegisterEnum method as follows.

  • 在Module.cs(Module.vb)文件中,使用枚举处理帮助器.寄存器Enum方法,在ModuleBase后代的构造函数中注册优先级枚举类型,如下所示。

    using DevExpress.Data.Filtering;
    //...
    public sealed partial class MySolutionModule : ModuleBase {
    public MySolutionModule() {
    InitializeComponent();
    EnumProcessingHelper.RegisterEnum(typeof(MySolution.Module.BusinessObjects.DemoTask.Priority));
    //...
    }
    //...
    }
  • Use the code below to initialize the newly added Priority property when a DemoTask object is created.

  • 在创建 DemoTask 对象时,使用以下代码初始化新添加的"优先"属性。

public class DemoTask : Task {
public DemoTask() : base() {
//...
Priority = Priority.Normal;
}
//...
}
  • The constructor will be executed when the new DemoTask object is created. As a result, the Priority property will be initialized with the specified value.

  • 创建新的 DemoTask 对象时,将执行构造函数。因此,将用指定的值初始化"Priority"属性。
  • Run the WinForms or ASP.NET application. Create a new DemoTask object by selecting DemoTask in the drop-down list of the New () button. (In the Detail View that represents the newly created DemoTask object, note that the Priority property is set to Normal, as declared in the code above.) Notice that the enumeration property is automatically displayed by the combo box editor.

  • 运行 WinForms 或ASP.NET应用程序。通过在"新建(new_dropdown_btn)"按钮的下拉列表中选择"演示任务",创建新的"演示任务"对象。(在表示新创建的 DemoTask 对象的详细信息视图中,请注意,优先级属性设置为"正常",如上述代码中声明的那样。请注意,枚举属性由组合框编辑器自动显示。

You can see the code demonstrated in this lesson in the MySolution.Module | Business Objects | DemoTask.cs (DemoTask.vb) file of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.

您可以在 MySolution.模块中看到本课中演示的代码。业务对象 |DemoTask.cs (DemoTask.vb) 文件与 XAF 一起安装的 EF 演示(代码优先)文件。默认情况下,EF 演示(代码优先)应用程序安装在 %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst 中。

Initialize a Property After Creating an Object创建对象后初始化属性 即如何设置对象的默认值(EF)的更多相关文章

  1. Initialize a Property After Creating an Object 创建对象后初始化属性 (XPO)

    In this lesson, you will learn how to set the default value for a particular property of a business ...

  2. Invalid default value for prop "value": Props with type Object/Array must use a factory function to return the default value.(props default 数组/对象的默认值应当由一个工厂函数返回)

    Invalid default value for prop "value": Props with type Object/Array must use a factory fu ...

  3. Creating default object from empty value in PHP?

      Your new environment may have E_STRICT warnings enabled in error_reporting if it is PHP <= 5.3, ...

  4. 在使用Ibatis查询数据返回时,报如下错误:java ibatis The error happened while setting a property on the result object

    问题: 在使用Ibatis查询数据返回时,报如下错误: [com.show.add.proxy.SqlMapClientTemplateProxy]com.ibatis.common.jdbc.exc ...

  5. log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [File] to set object on [TF.Log.FileAppender]

    难受,香菇. 大概研究了两个多小时,搜了很多资料都没有很完美的答案,最后突然脑子就一闪一闪,才弄明白咋回事. log4net:ERROR XmlHierarchyConfigurator: Canno ...

  6. hp警告Creating default object from empty value 问题的解决方法

    hp警告Creating default object from empty value 问题的解决方法 解决方法是找到报错的位置然后看哪个变量是没有初始化而直接使用的,将这个变量先实例化一个空类.如 ...

  7. Adding property to a json object in C#

    Adding property to a json object in C#   you can do it with a dynamic object dynamic obj = JsonConve ...

  8. Wordpress里提示警告信息creating default object from empty value in *** 的解决方法

    PHP里提示 Creating default object from empty value 的问题,一般是由于PHP版升级的原因,PHP 5.4 以上的版本一般会报这个错误.PHP的解决方法:找到 ...

  9. JS面向对象(3) -- Object类,静态属性,闭包,私有属性, call和apply的使用,继承的三种实现方法

    相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...

随机推荐

  1. 浏览器及Windows常用快捷键汇总

    浏览器常用快捷键: F5 刷新 Ctrl+N 打开新窗口 Ctrl+T 打开新标签 Ctrl +  O  打开浏览器的时候打开文件 Ctrl+Shift+N 隐身模式打开窗口 F2 F3 切换  Ct ...

  2. python __iter__和__getitem__区别

    __getitem__ 单独实现这个魔法函数,可以让这个类成为一个可迭代的对象,并且可以通过使用下标获取类中元素值下标的元素 class Library(object): def __init__(s ...

  3. RK3399安装Qt

    更新软件源.升级软件 sudo apt-get update sudo apt-get upgrade 安装Qt sudo apt-get install qt5-default sudo apt-g ...

  4. table-layout:fixed

    table-layout: fixed; 在table上设置上面属性后,如果不设置td的宽度,那么所有td的宽度平分总table宽度.如果设置了td的宽度,则以设置的宽度为准. table-layou ...

  5. (转)Python- sklearn之最小二乘法

    最小二乘法:https://baike.baidu.com/item/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%98%E6%B3%95/2522346?fr=aladdin ...

  6. 用两种以上的 方式实现一个方法或者对象,调用时打印"你好xx",已定义的代码不能做修改,自己编译的不能出现"你好"? (Javasctript)

    先上代码 const obj = { say(){ Array.from(arguments).forEach(item=>{ console.log(`${this.str} ${item}` ...

  7. OpenCV:获取图像当中某一点的坐标

    import numpy as np image=np.zeros((300,300,3),dtype='uint8') (cx,cy)=image.shape[1]//2,image.shape[0 ...

  8. swoole2——Worker与TaskWorker进程

    1.swoole 的进程模型 swoole是一个多进程模型的框架,当启动一个进程swoole应用时,一共会创建2+n+m个线程,n为worker进程数,m为TaskWorker进程数,1个master ...

  9. scp跨服务器拷贝,后台运行

    [转载]原文:https://blog.csdn.net/u013091013/article/details/68941250 通常情况下,我门在同一台服务器拷贝数据最常用的命令便是cp,如果要在不 ...

  10. [日常] windows下使用vscode配合xebug调试php脚本

    windows下使用vscode配合xebug调试php脚本 要下载有php_xebug.dll扩展的版本,最新版可能没有这个扩展,php7.3应该是有的,php7.3.4好像没有默认是不加载这个扩展 ...