1

This is my model class

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

And this is my query method:

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

The JSON returned is

[
{
    "$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"
}
]

How can I avoid that $id in the returned JSON as I already have my idLog?

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
nano
  • 2,511
  • 4
  • 25
  • 42
  • possible duplicate of [how to remove $id during JSON serialization](http://stackoverflow.com/questions/11542144/how-to-remove-id-during-json-serialization) – Hamid Pourjam Jun 13 '15 at 20:38
  • it's correct that the answer is the same of that other question, but initially I had no idea the problem was due to JSON serialization. I thought it was a matter of the entity-framework or my model table. – nano Jun 14 '15 at 08:19

1 Answers1

2

use this to configure the json serializer

var json = config.Formatters.JsonFormatter;
        json.SerializerSettings.PreserveReferencesHandling =
            Newtonsoft.Json.PreserveReferencesHandling.None;
Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74