我正在对数据库运行此查询:
var result = (from leads in dc.T_DM_FactDemandeWebLeads
join demands in dc.T_DM_DimDemandeWebs on leads.DemandeWeb_FK equals demands.DemandeWeb_PK
join temps in dc.T_DM_Temps on demands.DateDemande_FK equals temps.Temps_PK
where leads.longitudeClient != null && (Convert.ToInt32(leads.GeolocDistanceRouteDistrib) > 1000*30) && (temps.Date > new DateTime(2000, 1, 1).Date)
select new Lead
{
lng = leads.longitudeClient,
lat = leads.latitudeClient,
distance = leads.GeolocDistanceRouteDistrib
}).Take(1000000);
问题:这条线有问题:
(Convert.ToInt32(leads.GeolocDistanceRouteDistrib) > 1000*30)
作为leads.GeolocDistanceRouteDistrib 是一个VARCHAR,它在某些情况下采用“未知”,导致格式异常:
Conversion failed when converting the varchar value 'Unknown' to data type int.
这个问题到这里就解决了,但是方法不能转换成SQL。
问题:有没有办法重写查询,以便在查询执行期间完成转换?