Limiting query size with entity framework

后端 未结 3 1157
悲哀的现实
悲哀的现实 2020-12-25 14:43

this is a simple question (I think), but I have not been able to find a solution. I know with other types of queries, you can add a limit clause that makes the query only re

相关标签:
3条回答
  • 2020-12-25 15:14

    sure.. for example you can do it like this:

    var productQuery = from b in solutionContext.Version
                               where b.Product.ID != 1 && b.VersionNumber == b.Product.ActiveNumber
                               orderby b.Product.LastNumber
                               select b;
    
    var limitedProductQuery = productQuery.Take(25);
    

    also you may need this for paging results:

    var pagedProductQuery = productQuery.Skip(25 * page).Take(25)
    
    0 讨论(0)
  • 2020-12-25 15:30

    What you're looking for is Take:

    var productQuery = (from b in solutionContext.Version
                       where b.Product.ID != 1 
                           && b.VersionNumber == b.Product.ActiveNumber
                       orderby b.Product.LastNumber
                       select b).Take(25);
    
    0 讨论(0)
  • 2020-12-25 15:32
    var productQuery = (from b in solutionContext.Version
                               where b.Product.ID != 1 && b.VersionNumber == b.Product.ActiveNumber
                               orderby b.Product.LastNumber
                               select b).Take(25);
    
    0 讨论(0)
提交回复
热议问题