什么是属性添加到自动生成的实体(使用VS2010和EF4)的最佳方法 [英] What is the best way to add attributes to auto-generated entities (using VS2010 and EF4)

查看:122
本文介绍了什么是属性添加到自动生成的实体(使用VS2010和EF4)的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC2具有使用属性上的实体(验证和扩展HTML辅助类等)的大力支持。

如果我生成使用VS2010 EF4实体数据模型数据库我的模型(EDMX和它的CS类),我想添加属性
 上的一些实体。什么是最好的做法?我应该如何应对更新模型(添加更多的字段/表到数据库中,并将它们合并到EDMX) - 将它让我的属性或生成新的CS文件删除一切


  

(此文件的手动更改可能导致
  在不同寻常的行为
  应用程序。)


  
  

(手动更改此
  文件如果code被覆盖
  再生。)



解决方案

通常你会创建所谓的部分类来扩展你的自动生成的对象。

添加属性生成的类

添加验证属性,以生成的属性

ASP.NET MVC2 has strong support for using attributes on entities (validation, and extending Html helper class and more).

If I generated my Model from the Database using VS2010 EF4 Entity Data Model (edmx and it's cs class), And I want to add attributes on some of the entities. what would be the best practice ? how should I cope with updating the model (adding more fields / tables to the database and merging them into the edmx) - will it keep my attributes or generate a new cs file erasing everything ?

(Manual changes to this file may cause unexpected behavior in your application.)

(Manual changes to this file will be overwritten if the code is regenerated.)

解决方案

Generally you'd create what is called partial classes to extend your auto-generated objects.

Adding Attributes to Generated Classes

Adding Validation Attributes to Generated Properties

这篇关于什么是属性添加到自动生成的实体(使用VS2010和EF4)的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆