【发布时间】:2025-12-12 21:55:01
【问题描述】:
我正在使用 MVC .NET 制作网站。
由于我是一个先学习设计数据库的老派程序员,所以我选择了数据库优先方法。我还使用“代码生成”来创建扩展名为 .tt 的文件。到目前为止,一切正常,除了一件让我烦恼的事情。
经典场景:
- 我意识到我缺少一个字段
- 我在数据库中添加了字段。
- 我进入 edmx 并选择从数据库中更新模型。
然后我回到我的代码,并删除了我放在模型字段顶部的特殊 DisplayName 标记之类的东西。
例如,如果我有这个:
public partial class Blog
{
public Blog()
{
this.BlogComments = new HashSet<BlogComment>();
}
public int IDBlog { get; set; }
public string Title { get; set; }
[AllowHtml]
public string Content { get; set; }
public System.DateTime DateCreated { get; set; }
public string Author { get; set; }
public virtual ICollection<BlogComment> BlogComments { get; set; }
}
会变成
public partial class Blog
{
public Blog()
{
this.BlogComments = new HashSet<BlogComment>();
}
public int IDBlog { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public System.DateTime DateCreated { get; set; }
public string Author { get; set; }
public virtual ICollection<BlogComment> BlogComments { get; set; }
}
这是因为[AllowHtml] 是在上一代模型之后添加的。有没有办法更新表格而不删除我在生成后添加的所有标签?我怎样才能做到这一点?
现在,我通过使用 SVN 进行一些还原来解决这个问题,但它很快就会变得无法管理。
谢谢
【问题讨论】:
标签: c# asp.net-mvc-3 entity-framework-4 database-first