Created
April 18, 2024 04:43
-
-
Save SteffenBlake/1580c9e6a7d307905417d5769b830e93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class QueryableExtensions | |
{ | |
public static IQueryable<JoinMapper<TA, TB>> Join<TA, TB, TKey>( | |
this IQueryable<TA> outer, | |
IQueryable<TB> inner, | |
Expression<Func<TA, TKey>> outerSelector, | |
Expression<Func<TB, TKey>> innerSelector | |
) | |
{ | |
return outer.Join( | |
inner, | |
outerSelector, | |
innerSelector, | |
(a, b) => new JoinMapper<TA, TB> | |
{ | |
A = a, | |
B = b | |
} | |
); | |
} | |
public static IQueryable<JoinMapper<TA, TB, TC>> Join<TA, TB, TC, TKey>( | |
this IQueryable<JoinMapper<TA, TB>> outer, | |
IQueryable<TC> inner, | |
Expression<Func<JoinMapper<TA, TB>, TKey>> outerSelector, | |
Expression<Func<TC, TKey>> innerSelector | |
) | |
{ | |
return outer.Join( | |
inner, | |
outerSelector, | |
innerSelector, | |
(ab, c) => new JoinMapper<TA, TB, TC> | |
{ | |
A = ab.A, | |
B = ab.B, | |
C = c | |
} | |
); | |
} | |
public static IQueryable<JoinMapper<TA, TB, TC, TD>> Join<TA, TB, TC, TD, TKey>( | |
this IQueryable<JoinMapper<TA, TB, TC>> outer, | |
IQueryable<TD> inner, | |
Expression<Func<JoinMapper<TA, TB, TC>, TKey>> outerSelector, | |
Expression<Func<TD, TKey>> innerSelector | |
) | |
{ | |
return outer.Join( | |
inner, | |
outerSelector, | |
innerSelector, | |
(abc, d) => new JoinMapper<TA, TB, TC, TD> | |
{ | |
A = abc.A, | |
B = abc.B, | |
C = abc.C, | |
D = d | |
} | |
); | |
} | |
} | |
public class JoinMapper<TA, TB> | |
{ | |
public required TA A { get; init; } | |
public required TB B { get; init; } | |
} | |
public class JoinMapper<TA, TB, TC> | |
{ | |
public required TA A { get; init; } | |
public required TB B { get; init; } | |
public required TC C { get; init; } | |
} | |
public class JoinMapper<TA, TB, TC, TD> | |
{ | |
public required TA A { get; init; } | |
public required TB B { get; init; } | |
public required TC C { get; init; } | |
public required TD D { get; init; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment