Entity Framework Ordering Includes

前端 未结 7 1363
孤城傲影
孤城傲影 2020-11-27 21:11

I am trying to get something like the following to work:

_dbmsParentSections = FactoryTools.Factory.PdfSections
                        .Include(x => x.Ch         


        
7条回答
  •  再見小時候
    2020-11-27 21:46

    Generally if you're using a bunch of includes, it's because you need to access child properties in a view. What I do is order the child collection when I need to access it in a view.

    For example, I might build some Include statements for a master/detail form. There's no sense ordering this at the initial EF query. Instead, why not order these child records at the view level when you're actually accessing them?

    I might have a survey with multiple survey questions. If I want to present the questions in a particular order at do it at the partial view level when I'm passing the model child collection to the partial view.

    @Html.Partial("_ResponsesPartial",Model.SurveyResponses.OrderBy(x => 
    x.QuestionId))
    

提交回复
热议问题