Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在不更改数据库的情况下更改模型?_C#_Entity Framework - Fatal编程技术网

C# 在不更改数据库的情况下更改模型?

C# 在不更改数据库的情况下更改模型?,c#,entity-framework,C#,Entity Framework,我有一个用来填充数据库的模型 public class Account { public int NumberOfPayPeriods { get { return 24; } } public decimal YearAmount { get; set; } public decimal PlanTotal { get { return NumberOfPayPeriods*YearAmount; } } } 我需要将NumberOfP

我有一个用来填充数据库的模型

public class Account
{
    public int NumberOfPayPeriods { get { return 24; } }
    public decimal YearAmount { get; set; }
    public decimal PlanTotal
    {
        get { return NumberOfPayPeriods*YearAmount; }
    }
}
我需要将
NumberOfPayPeriods
属性从一个
get
更改为一个
get;设置

但是,当我更改此选项时,会得到一个
EntityCommandExecutionException
(无效列名)。我假设这是因为它试图将其映射到以前不存在此类列的数据库(因为它只是一个get)


我有没有办法把这个换成一个get;设置不必删除表?那里有许多重要数据无法丢失或重新创建。

在不希望存储的属性上添加一个
[notmap]
属性

public class Account
{
    [NotMapped]
    public int NumberOfPayPeriods { get { return 24; } set { ... } }
    public decimal YearAmount { get; set; }
    public decimal PlanTotal
    {
        get { return NumberOfPayPeriods*YearAmount; }
    }
}

在不希望存储的属性上添加
[NotMapped]
属性

public class Account
{
    [NotMapped]
    public int NumberOfPayPeriods { get { return 24; } set { ... } }
    public decimal YearAmount { get; set; }
    public decimal PlanTotal
    {
        get { return NumberOfPayPeriods*YearAmount; }
    }
}