Initialize a Property After Creating an Object创建对象后初始化属性 即如何设置对象的默认值(EF)
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)的更多相关文章
- 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 ...
- 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 ...
- 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, ...
- 在使用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 ...
- log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [File] to set object on [TF.Log.FileAppender]
难受,香菇. 大概研究了两个多小时,搜了很多资料都没有很完美的答案,最后突然脑子就一闪一闪,才弄明白咋回事. log4net:ERROR XmlHierarchyConfigurator: Canno ...
- hp警告Creating default object from empty value 问题的解决方法
hp警告Creating default object from empty value 问题的解决方法 解决方法是找到报错的位置然后看哪个变量是没有初始化而直接使用的,将这个变量先实例化一个空类.如 ...
- 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 ...
- Wordpress里提示警告信息creating default object from empty value in *** 的解决方法
PHP里提示 Creating default object from empty value 的问题,一般是由于PHP版升级的原因,PHP 5.4 以上的版本一般会报这个错误.PHP的解决方法:找到 ...
- JS面向对象(3) -- Object类,静态属性,闭包,私有属性, call和apply的使用,继承的三种实现方法
相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...
随机推荐
- windows本地连不上虚拟机redis服务完美解决
检查本机与虚拟机是否可以互相ping通,如本机IP:192.168.22.111 虚拟机IP:192.168.44.129 (设置虚拟机静态IP已设置) 本机 win+R 输入cmd 进入dos 输 ...
- Ruby入门1
由于部门的自动化是由一个前辈实现的,他使用的Ruby的语言来实现的,所以需要学习一下Ruby语言,争取在15天左右可以掌握Ruby语言!加油~~~ 1.常量&变量 # 1.常量 # 一般用大写 ...
- (四十四)c#Winform自定义控件-水波-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- C# 管道通信 (client —— server)Framework2.0版本也可用
//管道服务类public class PipServer { [DllImport("kernel32.dll", SetLastError = true)] public st ...
- In .net 4.8,calculate the time cost of serialization in BinaryFormatter,NewtonSoft.json,and System.Text.Json.JsonSerializer.Serialize
using ConsoleApp390.Model; using Newtonsoft.Json; using System; using System.Collections.Generic; us ...
- 缓冲字符流 java.io.BufferedWriter ,java.io.BufferedReader,缓冲字符输出流:PrintWriter
package seday07; import java.io.IOException;import java.io.PrintWriter; /*** @author xingsir * 缓冲字符流 ...
- google跟踪代码管理器gtm无法给相同class元素绑定click事件埋点解决
Google 跟踪代码管理器是一个跟踪代码管理系统 (TMS),可以帮助您快速轻松地更新网站或移动应用上的跟踪代码及相关代码段(统称为“代码”).将一小段跟踪代码管理器代码添加到项目后,您可以通过网页 ...
- ABAP 字符串换行符处理
今天发现BW系统从K3系统数据库抽取会计科目的描述时,转换出错. 从监控器上看是值2KO 845 412D#有问题,但不知道有什么问题,检查后感觉是符号#的问题. 在转换中添加代码,替换#,发现没有起 ...
- 个人项目-WC(C/C++ 兼容Linux和Windows)
一.Github地址 https://github.com/S-TRAVELER/WC 实现的功能: 支持 -c 支持 -w 支持 -l 支持 -s 支持 -a 图形界面 多参数(文件名或通配符表达式 ...
- Unity如何更改精灵中心点
Unity虽然可以改中心点但是仅支持几个特定位置. 如果是一个你是切割的精灵,则可以进入精灵编辑器中调整 打开精灵编辑器后按调整如下图所示的pivot选项,我在这里把精灵调整成了右上. 在精灵编辑 ...