我有以下表格:C# - 左外连接lambda表达式错误
Table1
{
Code //string
Desc //string
}
Table2
{
Code //string
Value //decimal?
}
我需要LEFT JOIN表和每个表2编号/价值缺失我想显示代码= Table1.Code,说明= Table1.Desc和Value = null或空白。
我tryied以下lambda表达式:
var result = Table1.GroupJoin(
Table2,
x => x.Code,
y => y.Code,
(x, y) => g
.Select(c => new { x.Code, x.Desc, Value = y.Value })
.DefaultIfEmpty(new { x.Code, x.Desc, Value = null }))
.SelectMany(g => g);
并得到了这些错误:
用于方法的类型参数“System.Linq.Enumerable.DefaultIfEmpty(System.Collections.Generic.IEnumerable,TSource )'不能从使用情况中推断出来。尝试明确指定类型参数。
无法指定匿名类型属性
于是,我改变了... ... DefaultIfEmpty值= 0} ...
,并得到这些错误: 'System.Collections.Generic.IEnumerable'不包含'DefaultIfEmpty'的定义,并且最佳扩展方法重载'System.Linq.Queryable.DefaultIfEmpty(System.Linq.IQueryable,TSource)'有一些无效参数
实例参数:无法从 'System.Collections.Generic.IEnumerable' 到 'System.Linq.IQueryable' 转换
任何想法解决这个错误?
当然!非常感谢你!!! – rafilho