How to join results from two different sets in LINQ?

Posted by Inez on Stack Overflow See other posts from Stack Overflow or by Inez
Published on 2010-04-28T22:11:21Z Indexed on 2010/04/28 22:17 UTC
Read the original article Hit count: 268

Filed under:
|

Hi,

I get some data about customers in my database with this method:

    public List<KlientViewModel> GetListOfKlientViewModel()
    {
        List<KlientViewModel> list = _klientRepository.List().Select(k => new KlientViewModel
            {
                Id = k.Id,
                Imie = k.Imie,
                Nazwisko = k.Nazwisko,
                Nazwa = k.Nazwa,
                SposobPlatnosci = k.SposobPlatnosci,
            }).ToList();
        return list;
    }

but also I have another method which counts value for extra field in KlientViewModel - field called 'Naleznosci'.

I have another method which counts value for this field based on customers ids, it looks like this:

public Dictionary<int, decimal> GetNaleznosc(List<int> klientIds)
{
    return klientIds.ToDictionary(klientId => klientId, klientId => (from z in _zdarzenieRepository.List()
         from c in z.Klient.Cennik
         where z.TypZdarzenia == (int) TypyZdarzen.Sprzedaz && z.IdTowar == c.IdTowar && z.Sprzedaz.Data >= c.Od && (z.Sprzedaz.Data < c.Do || c.Do == null) && z.Klient.Id == klientId
         select z.Ilosc*(z.Kwota > 0 ? z.Kwota : c.Cena)).Sum() ?? 0);
}

So what I want to do is to join data from method GetNaleznosc with data generated in method GetListOfKlientViewModel. I call GetNaleznosc like this:

GetNaleznosc(list.Select(k => k.Id).ToList())

but don't know what to do next.

© Stack Overflow or respective owner

Related posts about linq-to-entities

Related posts about LINQ