var query = (from p in pageData join z in zcData on p.ZC equals z.ItemID into j_join from x in j_join.DefaultIfEmpty() group p by x.IName into g select new { g.Key, countNub = g.Count() }).ToList();
但是p.ZC是String类型字段,z.ItemID是Int类型字段,编译不会出错,但是执行时候会报:LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 错误。
下面是解决此问题的代码:(红色代码部分有变化)
query = (from p in pageData join z in zcData on p.ZC equals System.Data.Objects.SqlClient.SqlFunctions.StringConvert((double)z.ItemID) into j_join from x in j_join.DefaultIfEmpty() group p by x.IName into g select new { g.Key, countNub = g.Count() }).ToList();
网上找了很多,但是都是只是点了点,这个方法还是不错的,改动比较小。