LINQ和c#:如何添加字段,而不是映射到表列
本文关键字:映射 字段 何添加 添加 LINQ | 更新日期: 2023-09-27 18:18:05
我从数据库表中加载记录。我需要添加一个名为"temp"的字段,它不对应于任何表列。我如何添加这个字段?
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
}
}
使用[NotMapped]
属性
[NotMapped]
public string temp { get; set; }
任何具有NotMapped
属性的属性或类都将被排除在数据库映射之外。