I hate linq syntax. I use extension syntax so I can build up queries to refine them.
Either way - This is my stab:
var ret = Number.Select(item => new
{
A = item.Substring(0, 11),
B = item.Substring(14, 2),
C = item.Substring(19, 11),
D = item.Substring(33)
})
.SelectMany(n =>
Report.Where(
a => a.A == n.A && a.B == n.B
&& a.C == n.C && a.D == n.D &&
Filter.Type.Contains(a.Y))
.Select(a => new ReportData
{
X = a.X,
Y = a.Y,
}))
.Where(nr =>
Filter.Ma == null || !Filter.Ma.Any() || Filter.Ma.Contains(nr.Ma)
).ToList();
I couldn't really test it as I don't know what
Report
,
Filter
or
ReportData
, really look like
Update: Broken down into stages:
var q1 = Number.Select(item => new
{
A = item.Substring(0, 11),
B = item.Substring(14, 2),
C = item.Substring(19, 11),
D = item.Substring(33)
}).AsQueryable();
var q2 = q1.SelectMany(n =>
Report.Where(
a => a.A == n.A && a.B == n.B
&& a.C == n.C && a.D == n.D &&
Filter.Type.Contains(a.Y))
.Select(a => new ReportData
{
X = a.X,
Y = a.Y,
})).AsQueryable();
var ret = q2.Where(nr =>
Filter.Ma == null || !Filter.Ma.Any() || Filter.Ma.Contains(nr.Ma)
).ToList();