I have this error in this linq expression :
var naleznosci = (from nalTmp in db.Naleznosci
where nalTmp.idDziecko == idDziec
Sorry for being late to the party, but I after finding this, I thought this should be shared as it's the cleanest, fastest and also memory-saving implementation I could find.
Adapted to your example, you'd write:
public static IQueryable ToPayments(this IQueryable source)
{
Expression> createPayments = naleznosci => new Payments
{
Imie = source.Dziecko.Imie,
Nazwisko = source.Dziecko.Nazwisko,
Nazwa= source.Miesiace.Nazwa,
Kwota = source.Kwota,
NazwaRodzajuOplaty = source.RodzajeOplat.NazwaRodzajuOplaty,
NazwaTypuOplaty = source.RodzajeOplat.TypyOplat.NazwaTypuOplaty,
DataRozliczenia = source.DataRozliczenia,
TerminPlatnosci = source.TerminPlatnosci,
};
return source.Select(createPayments);
}
The big advantages here (as Damien Guard pointed out in the comments at the link) are:
var foo = createPayments(bar); as well as usage via myIQueryable.ToPayments() possible.