Search code examples
c#entity-frameworklinq-to-entities

c# LINQ Take for internal query


I have smth like this

DbContext.Level1.GroupBy(level1=> level1.field1, (field1, list1)=>
 new Level1{ 
    field1 = field1,
    level2List = list1.GroupBy (level2 = > level2.field2, (field2, list2) =>
       new Level2 {
          field2 = field2}
   ).Take(takeValue)
 }
).ToList()

takeValue could be 10, 20, 30. But sometimes I need to select all possible items. Is it possible somehow to allow Take to get all records?


Solution

  • I think the most readable solution would be inserting Int32.MaxValue into takeValue. If it exceeds the amount of actual values it'll retrieve the entire collection.