【发布时间】:2013-12-21 16:33:24
【问题描述】:
我有一个模型类定义为:
public class EventReg
{
public int ID { get; set; }
[Display(Name = "Event Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime EventDate { get; set; }
[Display(Name = "Event Time")]
[DataType(DataType.Time)]
[DisplayFormat(DataFormatString = "{0:t}", ApplyFormatInEditMode = true)]
public DateTime EventTime { get; set; }
public List<string> HashTags { get; set; }
public string Category { get; set; }
[Display(Name = "Registered by")]
public string UniqueId { get; set; }
public float Latitude { get; set; }
public float Longitude { get; set; }
public string Description { get; set; }
}
问题:
现在我真的不知道每个事件是否会有 category 和 Hash Tags。所以,我想将这些字段注册为 Nullable 但是当我将这些字段定义为 System.Nullable 用于 category 或 System.Nullable > 对于HashTags,出现
"The type string/List<string> must be non-nullable value type in order to use it as a parameter 'T' in the generic type or method'System.Nullable<T>'"错误。如何解决这个错误?我希望以后能够更新数据库架构,所以使用 包管理器控制台(添加迁移初始命令) 创建一个每次都会执行的 *datetime_initial.cs* 文件我调用更新数据库。但由于某种原因,字段 HashTags 未在创建的 datetime_initial.cs 文件中列出。为什么?
【问题讨论】:
-
这里的全部情况是,字符串数据类型在设计上已经 IS 可以为空。所以你不需要在这里做任何事情(而且你也不允许这样做)。
标签: asp.net asp.net-mvc entity-framework