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 partial class Address { public int AddressID { get; set; } public string street { get; set; } public string Town { get; set; } public string PostCode { get; set; } public string City { get; set; } } 我想通过合并所有其他字段来创

我的表中有以下列

public partial class Address
{
    public int AddressID { get; set; }
    public string street { get; set; }
    public string Town { get; set; }
    public string PostCode { get; set; }
    public string City { get; set; }
}
我想通过合并所有其他字段来创建一个新字段,但我不想在数据库中创建新字段

public partial class Address
{
        public int AddressID { get; set; }
        public string street { get; set; }
        public string Town { get; set; }
        public string PostCode { get; set; }
        public string City { get; set; }
        Public String FullAddress =street+Town+PostCode+City;   // the required new field 
}
我的问题是如何正确地编码它


谢谢

只需创建一个不带
设置器的属性

public string FullAddress
{
     get
     {
         return this.street + " " +
                this.Town + " " +
                this.PostCode + " " +
                this.City;
     }
}

实体框架将自动检测到它是一个仅getter的属性,并将忽略它(好像它真的是一个
GetFullAddress()
方法)。

提议的
FullAddress
属性也会有一个setter吗?不需要setter@haim770No它应该只是一个虚拟字段谢谢我得到了它。但现在我面临新的问题。我在EF中使用模型优先的方法。我在model.tt中修改了这个代码。但这一领域并没有在林克奎里表现出来