【发布时间】:2014-09-25 19:10:42
【问题描述】:
我是 ASP.Net 的新手,我正在尝试开发一个模型来表示系统中的日志,但是控制器向导(创建脚手架视图)和代码优先方法并没有创建所有列.
这是我的模型的定义:
namespace Project.Models
{
public enum SystemComponents : byte
{
Component1, Component2, Component3
}
public enum LogMessageCategory : byte
{
Warning, Error, Debug, Log
}
public class LogDbContext : DbContext
{
public DbSet<Log> Logs { get; set; }
}
public class Log
{
public int ID { get; set; }
[Required]
public SystemComponents AffectedComponent;
[Required]
public LogMessageCategory MessageCategory;
[Display(ResourceType = typeof(Resources.Resources), Name = "EventDate")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Required]
public DateTime EventDate { get; set; }
/// <summary>
/// Foreign Key that represents the event's emisor.
/// This can be both a User, or a System component
/// </summary>
public int ActorID { get; set; }
/// <summary>
/// Foreign Key that represents the event's emisor.
/// This can be both a User, or a System component
/// </summary>
public int ComponentID { get; set; }
}
我做错了什么?此外,在使用资源(用于国际化)的视图中显示此属性的正确方法是什么? (因为这个模型的实例将由系统创建,我不在乎如何在创建视图中显示字段)
另外,还有一个问题,我是否必须公开我的所有属性才能使用它们?在线教程没有解释这一点,但如果没有,则不会在数据库中创建字段。
P.D.我想我正在使用 EF 6.0(VS 2013 Premium)
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework ef-code-first