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时将属性应用于实体属性的更多相关文章

  1. 《Entity Framework 6 Recipes》中文翻译系列 (22) -----第五章 加载实体和导航属性之延迟加载

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第五章 加载实体和导航属性 实体框架提供了非常棒的建模环境,它允许开发人员可视化地使 ...

  2. 《Entity Framework 6 Recipes》中文翻译系列 (24) ------ 第五章 加载实体和导航属性之查询内存对象

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-4  查询内存对象 问题 你想使用模型中的实体对象,如果他们已经加载到上下文中, ...

  3. 《Entity Framework 6 Recipes》中文翻译系列 (28) ------ 第五章 加载实体和导航属性之测试实体是否加载与显式加载关联实体

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-11  测试实体引用或实体集合是否加载 问题 你想测试关联实体或实体集合是否已经 ...

  4. 关于Entity Framework自动关联查询与自动关联更新导航属性对应的实体注意事项说明

    一.首先了解下Entity Framework 自动关联查询: Entity Framework 自动关联查询,有三种方法:Lazy Loading(延迟加载),Eager Loading(预先加载) ...

  5. c#使用 Newtonsoft.Json 将entity转json时,忽略为null的属性

    c#使用 Newtonsoft.Json 将entity转json时,忽略为null的属性,直接在属性上加下面的特性 [JsonProperty(NullValueHandling=NullValue ...

  6. 实体entity、JavaBean、Model、POJO、domain的区别

    实体entity.JavaBean.Model.POJO.domain的区别Java Bean.POJO. Entity. VO , 其实都是java 对象,只不过用于不同场合罢了. 按照 Sprin ...

  7. Entity Framework(EF的Model First方法)

    EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...

  8. Propagation of Visual Entity Properties Under Bandwidth Constraints

    1. Introduction The Saga of Ryzom is a persistent massively-multiplayer online game (MMORPG) release ...

  9. Entity Framework 6 Recipes 2nd Edition(12-5)译 -> 自动删除相关联实体

    12-5. 自动删除相关联实体 问题 当一个实体被删除时,你想自动删除它相关联的实体 解决方案 假设你有一个表结构由一个course (科目), course 的classes (课程),以及enro ...

随机推荐

  1. MySQL+Keepalived高可用配置

    注意:首先关闭两台机器的防火墙 setenforce 0 Environment: 2台CentOS测试机器  安装好MySQL 1.两台机器安装keepalived yum -y install k ...

  2. react之高阶组件(一)

    当两个或多个组件有相同的地方,可以将相同的部分抽离出来 先创建三个组件A.B.C A.js import React, { Component } from 'react' class A exten ...

  3. 带着canvas去流浪系列之八 碰撞

    [摘要] canvas动画-碰撞仿真 示例代码托管在:http://www.github.com/dashnowords/blogs 经过前面章节相对枯燥的练习,相信你已经能够上手canvas的原生A ...

  4. php mysql_connect 在同一host下多数据库mysql_select_db()的bug .

    操作方法 创建两个数据库test1 test2 同一个host下面 分别在两个数据库中创建表 -- ---------------------------- -- Table structure fo ...

  5. Linux内核最顶层文档

    Linux 内核文档 该文件是 Linux 内核文档树中最顶层的,会随着内核一起更新:其目的是把散乱的文档集成为一个逻辑清晰的完整版,非常欢迎改善文档,如果想做出自己的贡献,加入vger.kernel ...

  6. 17-Python执行JS代码--PyExecJS、PyV8、Js2Py

    一.Python执行JS代码--PyExecJS.PyV8.Js2Py 1.1.PyExecJS PyExecJS的优点是您不需要照顾JavaScript环境.特别是,它可以在Windows环境中运行 ...

  7. 服务容错保护hystrix

    灾难性雪崩效应 如何解决灾难性雪崩效应 降级 超时降级.资源不足时(线程或信号量)降级,降级后可以配合降级接口返回托底数据.实现一个 fallback 方法, 当请求后端服务出现异常的时候, 可以使用 ...

  8. HDU3896 Greatest TC(双联通分量+倍增)

    Problem Description TC (Tian Chao) is magical place, as you all know...The railways and the rail-sta ...

  9. 攻略前端面试官(三):JS的原型和原型链

    本文在个人主页同步更新~ 背就完事了 介绍:一些知识点相关的面试题和答案 使用姿势:看答案前先尝试回答,看完后把答案收起来检验成果~ 面试官:什么是构造函数 答:构造函数的本质是一个普通函数,他的特点 ...

  10. 3年java开发面试BAT,你必须彻底搞定Maven!

    前言 现在的Java项目中,Maven随处可见. Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案,如果你搞不懂Maven,那么一个多模块的项目足以让你头疼,依赖 ...