I'm running this query against a database:
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);
Problem: This line is buggy:
(Convert.ToInt32(leads.GeolocDistanceRouteDistrib) > 1000*30)
as leads.GeolocDistanceRouteDistrib is a VARCHAR which takes "Unknown" in some cases, leading to a format exception:
Conversion failed when converting the varchar value 'Unknown' to data type int.
This problem is solved here, but the method cannot be converted to SQL.
Question: is there any way to rewrite the query so the conversion is done during the execution of the query?