实体框架 6 代码优先不创建所有列

Joh*_*n S 1 c# entity-framework entity-framework-6

我正在使用 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; }
}
Run Code Online (Sandbox Code Playgroud)

UpdateDate字段正在按预期创建,但不是CreateDate. 这是为什么?

mar*_*c_s 5

这是因为该字段是只读的,因为它只有一个吸气剂:

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; }
}
Run Code Online (Sandbox Code Playgroud)