Unable to convert MySQL query to LINQ

拈花ヽ惹草 提交于 2019-12-25 03:07:30

问题


I have already watched this solution but still, my question is same. I am unable to convert my MySQL query to LINQ. I am using LinqPad for it. I have created a connection. Executed my query and got the result. But the lambda section is empty.

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'

I want to convert this to LINQ. The model name is kesc

Update 1

I have tried to convert my MySQL to 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();

and the output is

{
 "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 });

The output contains multiple records for same data. In actual, there is only one record for 2018-05-16T18:39:52.

Any help would be highly appreciated.

来源:https://stackoverflow.com/questions/51057323/unable-to-convert-mysql-query-to-linq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!