无法将MySQL查询转换为LINQ

时间:2018-06-27 07:49:59

标签: c# mysql linq linqpad

我已经看过这个solution,但我的问题还是一样。我无法将我的MySQL查询转换为LINQ。我正在使用LinqPad。我创建了一个连接。执行我的查询并得到结果。但是lambda部分为空。

SELECT * 
FROM ( 
SELECT 
    @row := @row +1 AS rownum, zdjh,sjsj ,xhqd
FROM ( 
    SELECT @row :=0) r, `tj_xhqd` ORDER BY sjsj
) ranked 
WHERE rownum % 24= 0 AND zdjh = '002999001180' AND sjsj>='2018-02-24 08:38:11'

我想将其转换为LINQ。型号名称为kesc

更新1

我尝试将MySQL转换为LINQ

var mainDetails = kesc.tj_xhqd.Where(m => (m.zdjh == msn) && (m.sjsj >= dt)).AsEnumerable()
                              .Select((x, i) => new { MSN = x.zdjh, PingDateTime = x.sjsj, PingValue = x.xhqd, i = i })
                              .Where(x => x.i % interval == 0)
                              .ToList();

,输出为

{
 "details": [
   {
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 0
   },
   {
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 24
   },
   {
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 48
    },
   {
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 72
    },
   {
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 96
    },
.
.
.
.
.
{
    "MSN": "002999001180",
    "PingDateTime": "2018-05-16T18:39:52",
    "PingValue": "19",
    "i": 144
},
]
}

return Request.CreateResponse(HttpStatusCode.OK, new { details = mainDetails });

输出包含相同数据的多个记录。实际上,2018-05-16T18:39:52只有一条记录。

任何帮助将不胜感激。

0 个答案:

没有答案