c# - Entity Framework 6 code-first 不创建所有列
问题描述
我首先使用 EF6 和代码创建一个简单的表。除CreateDate
列外,所有字段均已创建。这是为什么?
public class InspectionPoint
{
public DateTime CreateDate { get; }
public string Detail { get; set; }
public int Id { get; set; }
public bool IsActive { get; set; }
public string Name { get; set; }
public string Question { get; set; }
public DateTime UpdateDate { get; set; }
}
该UpdateDate
字段正在按预期创建,但不是CreateDate
. 这是为什么?
解决方案
我想这是因为该字段是只读的,因为它只有一个吸气剂:
public class InspectionPoint
{
// only has "get"ter - therefore it's readonly
public DateTime CreateDate { get; }
// Every other field has both "get" and "set" and can be set to new values
public string Detail { get; set; }
public int Id { get; set; }
public bool IsActive { get; set; }
public string Name { get; set; }
public string Question { get; set; }
public DateTime UpdateDate { get; set; }
}
推荐阅读
- r - 左对齐在 Markdown html 输出文档 R 中不起作用
- python - micropython - ESP32 - MQTT 异常 4 - 谷歌云物联网
- javascript - 使用现有接口扩展接口
- javascript - 为什么我的元素没有出现?
- python - 如何使用 Python 查找 Word 文档的页数?
- java - 将第一个数组元素与最后一个交换,第二个与倒数第二个交换,依此类推
- python - 如何根据 django rest framefork 中的用户角色返回嵌套数据?
- numpy - 高级 numpy 布尔索引
- kubernetes - apply 是否根据滚动更新策略工作?
- javascript - 当我想给元素随机绝对位置时,如何防止元素重叠