I'm new in LINQ and Lambda expression. I'm not sure is there a way to shorten the result on this o.z.cust.cust.cust.bintAccountNo
. As you can see below, the more table needed to join the longer the resultselector cust.cust.cust
. Is there better way to shorten this Lambda expression's result selector?
POCO
public class Tbl1
{
[Key]
public long bintAccountNo{ get; set; }
}
public class Tbl2
{
[Key]
public int id { get; set; }
public long bintAccountNo{ get; set; }
}
public class Tbl3
{
[Key]
public int id { get; set; }
public long bintAccountNo{ get; set; }
}
public class Tbl4
{
[Key]
public int id { get; set; }
public long bintAccountNo{ get; set; }
public int intPartner{ get; set; }
}
public class Tbl5
{
[Key]
public int id { get; set; }
public int intPartner{ get; set; }
}
var b = (Tbl1
.GroupJoin(Tbl2, cust => cust.bintAccountNo, cust2 => cust2.bintAccountNo, (cust, cust2) => new { cust = cust, cust2 = cust2 })
.SelectMany(cust => cust.cust2.DefaultIfEmpty(), (cust, cust2) => new { cust = cust.cust, cust2 = cust2 })
.GroupJoin(Tbl3, c => c.cust.bintAccountNo, cust3 => cust3.bintAccountNo, (cust, cust3) => new { cust = cust, cust3 = cust3 })
.SelectMany(c => c.cust3.DefaultIfEmpty(), (cust, cust3) => new { cust = cust.cust, cust3 })
.Join(Tbl4, c => c.cust.cust.bintAccountNo, bp => bp.bintAccountNo, (cust, bp) => new { cust = cust, bp = bp })
.Join(Tbl5, z => z.bp.intPartner, part => part.intPartner, (z, part) => new { z = z, part = part }))
.Select(o => new
{
bintAccountNo = o.z.cust.cust.cust.bintAccountNo
}
Tbl1
& friends coming from? Is there not aDataContext
? Is this linq-to-sql or linq-to-entities /entity-framework? It would really help if you posted your actual real code; as it stands there's very little context here IMO. \$\endgroup\$