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 ...
随机推荐
- Android多线程之(一)——View.post()篇
前言 提起View.post(),相信不少童鞋一点都不陌生,它用得最多的有两个功能,使用简便而且实用: 1)在子线程中更新UI.从子线程中切换到主线程更新UI,不需要额外new一个Handler实例来 ...
- C# 设置、删除、读取Word文档背景——基于Spire.Cloud.Word
Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor().SetBackgroudImage().DeleteBackground().GetBackgroudColo ...
- openlayers6结合geoserver实现地图空间查询(附源码下载)
前言 之前写过一篇 openlayers4 版本的地图空间查询文章,但是由于是封装一层 js 代码写的,很多初学者看起来比较有点吃力,所以本篇文章重新写一篇地图空间查询文章,直接基于最新版本 open ...
- inline以及inline-block行内元素:vertical-align属性
- 前端js分页功能的实现,非常实用,新手必看
分享一个前端拿到数据后,自己生成分页的案例,案例如图显示,点击搜索后查询数据,显示数据列表,前端根据数据显示正确的分页 附上代码:代码附上,简单粗暴,自己用过的,兼容性好,没有封装,可以很好的分页原理 ...
- AJAX 多次调用,后面的会覆盖前面的内容/数据
1.有的时候,同一个请求链接,需要传递不同的参数,发起多个请求.因此我采用了for循环. 1.1 此处是需要传递的参数 function behavioranalysisReqstue(type) { ...
- WMB Commands
Check ports: mqsiprofile //Run this first mqsireportproperties MB8BROKER -e AddressSampleProvider -o ...
- 常见面试题之*args 和 **kwargs 的使用
def self_max(*args,**kwargs): print(args) print(kwargs) self_max(1,2,3,4,5,6,7,x=6,y=8,z=80,e=50) 输出 ...
- i++和++i的区别(主要为返回的值的区别)
初学者经常会搞不清i++,和++i 的关系 i++ 是把i的值拿过来,然后再+1++i 是吧i的值直接+1,之后再用
- Python 基础:入门必备知识
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:程序员野客 先看下咱们的基础目录1 标识符2 关键字3 引号4 编码5 ...