将字符串转换为长型并在asp.net MVC中的linq查询中使用 [英] Convert string to long type and use in a linq query within asp.net MVC

查看:67
本文介绍了将字符串转换为长型并在asp.net MVC中的linq查询中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在C#的Linq中将数据库中的字符串字段转换为长型-并在查询中使用它?

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?

在这里,tme是一个unix时间(长)-但是数据库中的字段targetdate是一个字符串.

Here, tme is a unix time (long) - but the field in the database, targetdate - is a string.

我尝试过:

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

但是我收到消息: LINQ to Entities无法识别方法'Int64 Parse(System.String)'方法,并且该方法无法转换为商店表达式.

我知道您可以在linq查询之前进行转换,但是有什么方法可以在linq查询中使用它?

I know you can convert before the linq query, but is there any way of using it WITHIN the linq query?

感谢您的帮助,

标记

推荐答案

尝试

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

如果您有很多记录,可以先按团队限制它们,然后按如下所示致电ToList

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);

或者您可以使用 AsEnumerable

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

这篇关于将字符串转换为长型并在asp.net MVC中的linq查询中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆