【发布时间】:2011-09-15 14:09:36
【问题描述】:
我正在使用 ASP.NET MVC 3 和实体框架制作网站。我想根据以下代码创建一个数据库:
public abstract class Document
{
public int DocId {get; set;}
public DocumentType DocType {get; set;}
public DateTime DateCreated {get; set;}
public DateTime DateUpdated {get; set;}
}
public class DocumentType{
public int TypeId {get; set;}
public int TypeName {get; set;}
}
public class News: Document
{
public string Title {get; set;}
public string Body {get; set;}
}
简短说明: 文档是诸如新闻(和其他)等内容类型的基础实体。新闻继承文档。每个文档(如新闻)都有其文档类型。例如,News 的类型名为“News”。
问题: 在我的情况下,是否可以通过添加继承 Document 实体的新实体并在创建实体时将新记录添加到现有 DocumentType 表(不删除数据库)来使用 Entity Framework Code First 更新数据库? 当我添加一个新实体时,我想要实现的所有目标 - 要在 DocumentType 表中添加一条新记录,以便此表数据始终是最新的。
如果可以实现,能否分享一些链接或者带来一些代码示例?
提前感谢您的帮助。
【问题讨论】:
标签: c# asp.net asp.net-mvc-3 entity-framework