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中修改了这个代码。但这一领域并没有在林克奎里表现出来