[英]LINQ and C#: How to add a field, not mapped to a table column
I load records from a database table. 我从数据库表中加载记录。 I need to add a field called "temp", which does not correspond to any table column. 我需要添加一个名为“temp”的字段,它不对应任何表列。 How can I add this field? 如何添加此字段?
namespace mynamespace.Models
{
public class alert
{
[Key]
public int id { get; set; }
public string text { get; set; }
public string temp { get; set; } //<--- this generates error
}
}
Thanks and regards. 谢谢并恭祝安康。
Use the [NotMapped]
attribute. 使用[NotMapped]
属性。
[NotMapped]
public string temp { get; set; }
Any property or class that has the NotMapped
attribute will be excluded from database mapping. 具有NotMapped
属性的任何属性或类都将从数据库映射中排除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.