Entity Framework 4 - What is the syntax for joining 2 tables then paging them?

后端 未结 4 1979
遇见更好的自我
遇见更好的自我 2021-02-03 22:54

I have the following linq-to-entities query with 2 joined tables that I would like to add pagination to:

IQueryable data = from inventory         


        
4条回答
  •  时光说笑
    2021-02-03 23:57

    Add following line to your query

    var pagedQuery = data.Skip(PageIndex * PageSize).Take(PageSize); 
    

    The data variable is IQueryable, so you can put add skip & take method on it. And if you have relationship between Product & Variant, you donot really require to have join explicitly, you can refer the variant something like this

    IQueryable data = 
                 from inventory in objContext.ProductInventory
                 where inventory.ProductId == productId && inventory.StoreId == storeId
                 orderby inventory.variant.SortOrder
                 select new()
                 {
                     property1 = inventory.Variant.VariantId,
                     //rest of the properties go here
                 }
    pagedQuery = data.Skip(PageIndex * PageSize).Take(PageSize); 
    

提交回复
热议问题