How to: Apply Attributes to Entity Properties when Using Model First 如何:在ModelFirst时将属性应用于实体属性
In a Model First data model, object properties are declared in the designer-generated files, and you cannot decorate them with the required built-in attributes directly. The workaround is to apply the MetadataType attribute to a class, create the metadata class, and apply the required attributes to the properties of the metadata. The code below illustrates this approach using the data model from the How to: Use the Entity Framework Model First in XAF example.
在 Model First 数据模型中,对象属性在设计器生成的文件中声明,并且不能直接使用所需的内置属性来修饰它们。解决方法是将 MetadataType 属性应用于类,创建元数据类,并将所需的属性应用于元数据的属性。下面的代码使用 XAF 示例中":首先使用实体框架模型"中的数据模型演示了此方法。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4374
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E4374
.
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using DevExpress.ExpressApp.DC;
// ...
[MetadataType(typeof(EmployeeMetadata))]
public partial class Employee {
}
public class EmployeeMetadata {
[Browsable(false)]
public Int32 Id { get; set; }
}
//...
[MetadataType(typeof(TaskMetadata))]
public partial class Task {
}
public class TaskMetadata {
[Browsable(false)]
public Int32 Id { get; set; }
[FieldSize(FieldSizeAttribute.Unlimited)]
public String Description { get; set; }
}
A reference to System.ComponentModel.DataAnnotations is required to compile the code above. Here, we use the Browsable attribute to hide the Id properties (which are key properties in our data model) from the UI. The FieldSizeAttribute specifies that an unlimited number of characters can be stored in the Task.Description property, so a multiline editor will be used for this property in the UI.
要编译上面的代码,需要引用 System.组件模型.Data 注释。在这里,我们使用可浏览属性从 UI 中隐藏 Id 属性(这是数据模型中的关键属性)。
FieldSize属性指定可以在 Task.描述属性中存储无限数量的字符,因此在 UI 中,将使用多行编辑器来执行此属性。
How to: Apply Attributes to Entity Properties when Using Model First 如何:在ModelFirst时将属性应用于实体属性的更多相关文章
- 《Entity Framework 6 Recipes》中文翻译系列 (22) -----第五章 加载实体和导航属性之延迟加载
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第五章 加载实体和导航属性 实体框架提供了非常棒的建模环境,它允许开发人员可视化地使 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (24) ------ 第五章 加载实体和导航属性之查询内存对象
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-4 查询内存对象 问题 你想使用模型中的实体对象,如果他们已经加载到上下文中, ...
- 《Entity Framework 6 Recipes》中文翻译系列 (28) ------ 第五章 加载实体和导航属性之测试实体是否加载与显式加载关联实体
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-11 测试实体引用或实体集合是否加载 问题 你想测试关联实体或实体集合是否已经 ...
- 关于Entity Framework自动关联查询与自动关联更新导航属性对应的实体注意事项说明
一.首先了解下Entity Framework 自动关联查询: Entity Framework 自动关联查询,有三种方法:Lazy Loading(延迟加载),Eager Loading(预先加载) ...
- c#使用 Newtonsoft.Json 将entity转json时,忽略为null的属性
c#使用 Newtonsoft.Json 将entity转json时,忽略为null的属性,直接在属性上加下面的特性 [JsonProperty(NullValueHandling=NullValue ...
- 实体entity、JavaBean、Model、POJO、domain的区别
实体entity.JavaBean.Model.POJO.domain的区别Java Bean.POJO. Entity. VO , 其实都是java 对象,只不过用于不同场合罢了. 按照 Sprin ...
- Entity Framework(EF的Model First方法)
EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...
- Propagation of Visual Entity Properties Under Bandwidth Constraints
1. Introduction The Saga of Ryzom is a persistent massively-multiplayer online game (MMORPG) release ...
- Entity Framework 6 Recipes 2nd Edition(12-5)译 -> 自动删除相关联实体
12-5. 自动删除相关联实体 问题 当一个实体被删除时,你想自动删除它相关联的实体 解决方案 假设你有一个表结构由一个course (科目), course 的classes (课程),以及enro ...
随机推荐
- 不使用cookie记录用户信息
cookie是什么: cookie是由web服务器保存在用户浏览器(客户端)上的小文件,它可以包含用户信息,用户操作信息等等,无论何时访问服务器,只要同源,就能携带到服务端 常见方式 一般:请求一个接 ...
- Kubernetes增强型调度器Volcano算法分析
[摘要] Volcano 是基于 Kubernetes 的批处理系统,源自于华为云开源出来的.Volcano 方便 AI.大数据.基因.渲染等诸多行业通用计算框架接入,提供高性能任务调度引擎,高性能异 ...
- 深度研究:回归模型评价指标R2_score
回归模型的性能的评价指标主要有:RMSE(平方根误差).MAE(平均绝对误差).MSE(平均平方误差).R2_score.但是当量纲不同时,RMSE.MAE.MSE难以衡量模型效果好坏.这就需要用到R ...
- leetcode字节跳动专题(持续更新)
挑战字符串 无重复字符的最长子串 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最 ...
- 十大C++实战项目,你会几个?【高薪必备】
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:实验楼 市面上有很多C++的实战项目,从简单到进阶,学习每个项目都 ...
- iSensor APP 之 摄像头调试 MT9D001 MT9P031 测试小结 200万像素和500万像素摄像头
iSensor APP 之 摄像头调试 MT9D001 MT9P031 测试小结 iSensor app 非常适合调试各种摄像头,已测试通过的sensor有: l OV7670.OV7725.OV ...
- telnet远程登陆
这篇文章是第二次更新,内容为telnet远程登陆路由器,非常简单.直接进入正题,在网络配通的情况下,为路由器设置登陆密码和管理员密码,就可以通过pc机远程管理路由器或交换机. 目的: 网络拓扑图如下, ...
- tensorflow学习笔记——VGGNet
2014年,牛津大学计算机视觉组(Visual Geometry Group)和 Google DeepMind 公司的研究员一起研发了新的深度卷积神经网络:VGGNet ,并取得了ILSVRC201 ...
- linux自定义开机欢迎页面图案
1:编辑etc目录下motd文件 佛祖图案 [root@host1 ~]# vim /etc/motd _oo0oo_ 088888880 88" . "88 (| -_- |) ...
- JAVA 锁的终极状态
自旋锁 背景:互斥同步对性能最大的影响是阻塞,挂起和恢复线程都需要转入内核态中完成:并且通常情况下,共享数据的锁定状态只持续很短的一段时间,为了这很短的一段时间进行上下文切换并不值得. 原理:当一条线 ...