[转][C#]Linq 的扩展方法
标签:ret tin list() equal col lis rabl div where
public static class LinqEx
{
public static IEnumerable LeftExcludingJoin(this IEnumerable source,
IEnumerable inner,
Func pk,
Func fk,
Func result)
where TSource : class
where TInner : class
{
IEnumerable _result = Enumerable.Empty();
_result = from s in source
join i in inner
on pk(s) equals fk(i) into joinData
from left in joinData.DefaultIfEmpty()
where left == null
select result(s, left);
return _result;
}
public static IEnumerable LeftJoin(this IEnumerable source,
IEnumerable inner,
Func pk,
Func fk,
Func result)
where TSource : class
where TInner : class
{
IEnumerable _result = Enumerable.Empty();
_result = from s in source
join i in inner
on pk(s) equals fk(i) into joinData
from left in joinData.DefaultIfEmpty()
select result(s, left);
return _result;
}
public static IEnumerable RightExcludingJoin(this IEnumerable source,
IEnumerable inner,
Func pk,
Func fk,
Func result)
where TSource : class
where TInner : class
{
IEnumerable _result = Enumerable.Empty();
_result = from i in inner
join s in source
on fk(i) equals pk(s) into joinData
from right in joinData.DefaultIfEmpty()
where right == null
select result(right, i);
return _result;
}
public static IEnumerable FulltExcludingJoin(this IEnumerable source,
IEnumerable inner,
Func pk,
Func fk,
Func result)
where TSource : class
where TInner : class
{
var left = source.LeftJoin(inner, pk, fk, result).ToList();
var right = source.RightExcludingJoin(inner, pk, fk, result).ToList();
return left.Union(right);
}
}
[转][C#]Linq 的扩展方法
标签:ret tin list() equal col lis rabl div where
原文地址:https://www.cnblogs.com/z5337/p/10199817.html
评论