I'm getting this error :
Conversion failed when converting the varchar value 'Zon7' to data type int.
establishments = GetEstablishments(waters.Select(t => ReplaceZonToEmptyString(t.IdGeographie)));
public static int ReplaceZonToEmptyString(string zoneId)
{
zoneId.Replace("Zon", string.Empty);
var sbInput = zoneId.Replace(" ", string.Empty);
return Convert.ToInt32(sbInput.ToString());
}
public static IQueryable<Etablissement> GetEstablishments(IQueryable<int> ids)
{
return from zone in entities.Zones
where ids.Contains(zone.IdZone)
select zone.IdBatimentNavigation.IdEtablissementNavigation;
}
var result = establishments.ToList();
in database i have a column of type varchar the column name is 'IdGeographie' with values that start with 'Zon', something like this "ZonXXXX"
You are trying to compare a
VARCHARcolumn with values of typeint. One of these values will have to change and since it con not be the SQL column, it has to be the compare value:If the signature of the methods can't change, you have to do the conversion within
GetEstablishments:Note that in
waters.Select(t => ReplaceZonToEmptyString(t.IdGeographie)), the valuewatersmust be a materialized list of values (i.e. not another EF query), since your replace operation can not work within Entity Framework (in either of the options).