这是我的EF查询。
抛出例:无法比较类型'System.Collections.Generic.List`1 [[System.String,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]'的元素。仅原始类型,枚举
所有参数已满。
public List<User> GetLawyersData(List<Guid> IdList, List<string> selectedCountries, List<string> selectedCities, List<string> selectedDistricts, List<string> selectedOccupations, List<string> selectedProfessions)
{
var result = (from u in _userDbContext
join ui in _userInformationDbContext
on u.Id equals ui.UserID
join d in _districtDbContext
on ui.DistrictId equals d.Id
join c in _cityDbContext
on d.CityID equals c.Id
join co in _countryDbContext
on c.CountryID equals co.Id
join uo in _userOccupationInformationDbContext
on u.Id equals uo.UserID
join oc in _occupationDbContext
on uo.OccupationID equals oc.Id
join up in _userProfessionDbContext
on u.Id equals up.UserID
join pr in _professionDbContext
on up.ProfessionID equals pr.Id
where IdList.Contains(u.Id) &&
(selectedCountries != null && selectedCountries.Count > 0 ? selectedCountries.Contains(co.AutoId.ToString()) : true) && (selectedCities != null && selectedCities.Count > 0 ? selectedCities.Contains(c.AutoId.ToString()) : true)
&& (selectedDistricts != null && selectedDistricts.Count > 0 ? selectedDistricts.Contains(d.AutoId.ToString()) : true)
&& (selectedOccupations != null && selectedOccupations.Count > 0 ? selectedOccupations.Contains(oc.AutoId.ToString()) : true)
&& (selectedProfessions != null && selectedProfessions.Count > 0 ? selectedProfessions.Contains(pr.AutoId.ToString()) : true)
select u).ToList();
return result;
我该怎么办?
答案 0 :(得分:-1)
我认为,问题在于在linq查询中使用ToString()函数。在反序列化之前,不能在字段上使用toString()。因此,与其尝试在查询中调用ToString(),不如在事后对结果进行操作或比较确切的数据类型值。
数据库中没有ToString()操作的概念,这就是为什么您会出错。