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

后端 未结 4 1981
遇见更好的自我
遇见更好的自我 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:38

    My answer here based on the answer that is marked as true but here I add a new best practice of the code above

        var data= (from c in db.Categorie.AsQueryable().Join(db.CategoryMap,
                        cat=> cat.CategoryId, catmap => catmap.ChildCategoryId, 
        cat, catmap) => new { Category = cat, CategoryMap = catmap })
    select (c => c.Category)
    

    this is the best practice to use the Linq to entity because when you add AsQueryable() to your code; system will converts a generic System.Collections.Generic.IEnumerable to a generic System.Linq.IQueryable which is better for .Net engine to build this query at run time

    thank you Mr. Khumesh Kumawat

提交回复
热议问题