如何使计算的 属性 在 Entity Framework 中持久保存在数据库中

How to make a calculated property to persist in database in Entity Framework

考虑这个简单的问题 class:

puclic class Person
{
    public string FirstName {get; set; }
    public string LastName {get; set; }

    public string FullName
    {
        get
        {
            return FirstName + " " + LastName;
        }
    }
}

我希望数据库中也有 FullName 列及其相应的值。

问题:我怎么说Entity Framework6来考虑计算的属性列?

您可以添加空 保护 setter

public string FullName
{
    get
    {
        return FirstName + " " + LastName;
    }
    protected set {}
}