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

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

问题描述

ASP.NET MVC2对实体使用属性(验证和扩展Html帮助器等等)有很强的支持。

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

如果我从数据库生成了我的模型使用VS2010 EF4实体数据模型(edmx和它的cs类),我想在一些实体上添加属性
。最好的做法是什么?我应该如何处理更新模型(向数据库添加更多的字段/表并将其合并到edmx中) - 它会保留我的属性还是生成一个新的cs文件来擦除所有内容?

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.)


推荐答案

通常你会创建一个所谓的部分类< a>扩展自动生成的对象。

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

将属性添加到生成的类

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

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