Convert string to long type and use in a linq query within asp.net MVC

前端 未结 4 896
清酒与你
清酒与你 2021-01-21 13:43

Is it possible within Linq in C#, to convert a string field in a database, to a long type - and use it in the query?

Here, tme is a unix time (long) - but the field in t

4条回答
  •  半阙折子戏
    2021-01-21 14:12

    try

    var qbt = db.Calls.ToList()
    .Where(x => x.team == id && long.Parse(x.targetdate) <= tme);
    

    if you have many records you can limit them by team first and then call ToList like below

    var qbt = db.Calls.Where(x => x.team == id).ToList()
     .Where(i=>long.Parse(i.targetdate) <= tme);
    

    Or You can use AsEnumerable

    var qbt = db.Calls.AsEnumerable()
    .Where(x => x.team == id && long.Parse(x.targetdate) <= tme);
    

提交回复
热议问题