1

I have the following query which works but it just seems wrong, can this be shortened? also is the following bad for performance?

var projectBylineIDs = _neptuneUow.Projects.FindWhere(p => p.ID == 81)
                               .SelectMany(p => p.Batches)
                               .SelectMany(i => i.Items)
                               .SelectMany(b => b.ByLines)
                               .Select(b => b.ID)
                               .ToList();
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Farhad-Taran
  • 6,282
  • 15
  • 67
  • 121
  • This might produce many SQL queries, see this question: http://stackoverflow.com/questions/13721623/selectmany-creates-lots-of-sql-select-statements-instead-of-one-with-join – Ilya Kogan Jul 02 '13 at 10:42

1 Answers1

0

Don't see a bad practice here, if yo need this , do it.

What about performance. Performance is extremely context sensitive subject. Depends on context of your code executing against, it can be very harmful of executes pretty sweet.

The questions that might ask yourself: do you need really all that information, that after you nee to flatten in sequence ? Or just run some StoredProcedure on server, and get ready to show result.

Hope this helps.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • thanks for your reply, I only need the batch ID, eg the last select .Select(b => b.ID), is it possible to get that without all the other select statements? – Farhad-Taran Jul 03 '13 at 08:30
  • @xerxes: don't see other way then 1) rearchitecting your class for easier accessibility to that property 2) if not, *in some way* (linq or not) you need traverse inner lists to get to that field. So chose more appropriate way, that fits *your* requirements (performace, memeory efficiency, time you can spend on this...) – Tigran Jul 03 '13 at 08:33