Search Results

Search found 5 results on 1 pages for 'inez'.

Page 1/1 | 1 

  • Where to execute extra logic for linq to entities query?

    - by Inez
    Let say that I want to populate a list of CustomerViewModel which are built based on Customer Entity Framework model with some fields (like Balance) calculated separately. Below I have code which works for lists - it is implemented in my service layer, but also I want to execute this code when I just get one item from the database and execute is as well in different services where I'm accessing Customers data as well. How should I do this to ensure performance but to to not duplicate code - the one for calculating Balance? public List<CustomerViewModel> GetCustomerViewModelList() { IQueryable<CustomerViewModel> list = from k in _customerRepository.List() select new CustomerViewModel { Id = k.Id, Name = k.Name, Balance = k.Event.Where(z => z.EventType == (int) EventTypes.Income).Sum(z => z.Amount) }; return list.ToList(); }

    Read the article

  • How to join results from two different sets in LINQ?

    - by Inez
    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.

    Read the article

  • How cast in c#/.net 3.5 works? for types with '?'

    - by Inez
    This is my code which works public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : (decimal?) null; } and this one doesn't work public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : null; } giving the compilator error: Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between 'decimal' and '' I wonder why? any ideas?

    Read the article

  • How does cast in C#/.NET 3.5 work for types with '?'

    - by Inez
    This is my code which works public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : (decimal?) null; } and this one doesn't work public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : null; } giving the compiler error: Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between 'decimal' and '<null>' I wonder why? any ideas?

    Read the article

1