我正在做这样的事情:
List<Employees> employees = DB_Context.Employees.Where(p => p.id == empId).ToList();
使用属性:
ID
FirstName
姓氏
地址
我想覆盖Address
,并在真实地址之前添加一些文字,
例如文本:Client's address
。
如何返回字符串Client's address
+ 地址属性
答案 0 :(得分:1)
为此你不想“覆盖实体框架”,你想要一个投影。在LINQ中,您使用Select()
:
var employees = context.Employees
.Where(p => p.id == empId)
.Select(e => new Employee
{
ID = e.ID,
FirstName = e.FirstName,
LastName = e.LastName,
Address = "Client address: " + e.Address
})
.ToList();
您还可以公开非映射属性并指示您的同事使用该属性:
public class Employee
{
// Other properties
[NotMapped]
public string ClientAddress
{
get
{
return "Client address: " + Address;
}
}
}