实体框架查询返回我的主键加$id

本文关键字:id 我的 框架 查询 返回 实体 | 更新日期: 2023-09-27 17:56:08

这是我的模型类

public partial class TLog
{
    [Key]
    public int idLog { get; set; }
    public string description { get; set; }
    public System.DateTime insertDate { get; set; }
}

这是我的查询方法:

public static List<TLog> GetAllLogs()
    {
        var query = from log in dataContext.Log
                        select log;
        return query.ToList();
    }

返回的 JSON 是

[
{
    "$id": "1",
    "idLog": 1,
    "description": "Log1",
    "insertDate": "2015-06-13T17:32:02.053"
},
{
    "$id": "2",
    "idLog": 2,
    "description": "Log2",
    "insertDate": "2015-06-13T17:52:39.637"
}
]

如何避免返回的 JSON 中出现该$id,因为我已经拥有了 idLog?

实体框架查询返回我的主键加$id

使用它来配置 JSON 序列化程序

var json = config.Formatters.JsonFormatter;
        json.SerializerSettings.PreserveReferencesHandling =
            Newtonsoft.Json.PreserveReferencesHandling.None;
相关文章: