I know there is a way to do this, but I hit my head against the wall, trying to figure it out. This works great:
private GenericRecord CreateGeneric(GenericRecord g, Member m)
{
g.Member = m;
return g;
}
public IList<GenericRecord> ReportFromDatabase(DateTime startDate, DateTime endDate)
{
List<GenericRecord> returnRecords = new List<GenericRecord>();
returnRecords.AddRange(from r in pjRepository.Records
join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
where r.TransactionDate >= startDate && r.TransactionDate <= endDate
select CreateGeneric((GenericRecord)r, m));
return returnRecords;
}
But I know that there is a way to do this without the CreateGeneric function. How to choose inline delegate function?
returnRecords.AddRange(from r in pjRepository.Records
join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
where r.TransactionDate >= startDate && r.TransactionDate <= endDate
select (delegate
{
GenericRecord g = (GenericRecord)r;
g.Member = m;
return g;
}));
This gives me this exception:
The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
Edit: Another unsuccessful attempt
returnRecords.AddRange((from r in pjRepository.Records
join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
where r.TransactionDate >= startDate && r.TransactionDate <= endDate
select new { r, m }).Select(x =>
{
GenericRecord g = (GenericRecord)x.r;
g.Member = x.m;
return g;
}));
This gives me:
A lambda expression with an operator body cannot be converted to an expression tree.
source
share