将实体框架结果返回为JSON

时间:2016-04-07 08:56:52

标签: c# json linq wcf-data-services

我希望将我的linq查询结果恢复为json格式。我一直在寻找几个小时。

这是我的代码:

public IEnumerable<callersW> GetAllCallersF()
{
  testCDREntities1 context = this.CurrentDataSource;
  var query = (
    from oneCaller in CurrentDataSource.TestTables
    select new
    {
      Created = oneCaller.Created,
      Answered = oneCaller.Answered,
      Destroyed = oneCaller.Destroyed,
      CallerID = oneCaller.CallerId,
      CalledID = oneCaller.CalledId,
      DisconnectionCode = oneCaller.DisconnectionCode,
      RTP_Caller_G107MOS = oneCaller.RTP_Caller_G107MOS,
      RTP_Caller_LostPackets = oneCaller.RTP_Caller_LostPackets,
      RTP_Caller_MaxRfc3550Jitter = oneCaller.RTP_Caller_MaxRfc3550Jitter,
      RTP_Caller_MeanRfc3550Jitter = oneCaller.RTP_Caller_MeanRfc3550Jitter,
      RTP_Called_G107MOS = oneCaller.RTP_Called_G107MOS,
      RTP_Called_LostPackets = oneCaller.RTP_Called_LostPackets,
      RTP_Called_MaxRfc3550Jitter = oneCaller.RTP_Called_MaxRfc3550Jitter,
      RTP_Called_MeanRfc3550Jitter = oneCaller.RTP_Called_MeanRfc3550Jitter,
    }).ToList()
    .Select(x => new callersW
    {
      Created = Convert.ToDateTime(x.Created),
      Answered = Convert.ToDateTime(x.Answered),
      Destroyed = Convert.ToDateTime(x.Destroyed),
      CallerID = x.CallerID,
      CalledID = x.CalledID,
      DisconnectionCode = Convert.ToInt32(x.DisconnectionCode),
      RTP_Caller_G107MOS = Convert.ToDouble(x.RTP_Caller_G107MOS),
      RTP_Caller_LostPackets = Convert.ToDouble(x.RTP_Caller_LostPackets),
      RTP_Caller_MaxRfc3550Jitter = Convert.ToDouble(x.RTP_Caller_MaxRfc3550Jitter),
      RTP_Caller_MeanRfc3550Jitter = Convert.ToDouble(x.RTP_Caller_MeanRfc3550Jitter),
      RTP_Called_G107MOS = Convert.ToDouble(x.RTP_Called_G107MOS),
      RTP_Called_LostPackets = Convert.ToDouble(x.RTP_Called_LostPackets),
      RTP_Called_MaxRfc3550Jitter = Convert.ToDouble(x.RTP_Called_MaxRfc3550Jitter),
      RTP_Called_MeanRfc3550Jitter = Convert.ToDouble(x.RTP_Called_MeanRfc3550Jitter)
    }).ToList();

  return  query;
}

有人可以帮我这个吗?

0 个答案:

没有答案