linq to entity 发生异常,大侠帮忙看看,马上结贴
linq to entity 发生错误,大侠帮忙看看,马上结贴
有两个表,一个是地址表:Common_Address,一个是城市表Common_City,这个表的主键是省份和城市的复合键ProvinceID,和CityID,
join处发生错误:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.
------解决方案--------------------
有两个表,一个是地址表:Common_Address,一个是城市表Common_City,这个表的主键是省份和城市的复合键ProvinceID,和CityID,
join处发生错误:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.
- C# code
using (var context = new LswEntities()) { var query = from q in context.Common_Address join city in context.Common_City on new { CityID = q.CityID, ProvinceID = q.ProvinceID } equals new { CityID = city.CityID, ProvinceID = city.ProvinceID } into cityGroup select q; }
------解决方案--------------------
- C# code
using(var context = new LswEntities()) { var query = from q in context.Common_Address join city in context.Common_City on q.CityID equals city.CityID && q.ProvinceID equals city.ProvinceID select new { CityID = q.CityID, ProvinceID = q.ProvinceID }; }
------解决方案--------------------
你原来写的linq里把 into xxx 去掉。
var query = from q in context.Common_Address
join c in context.Common_City on
new { q.CityID, q.ProvinceID } equals
new { c.CityID, c.ProvinceID } into cityGroup
select q;