How to optimize Entity Framework Queries

后端 未结 3 2112
日久生厌
日久生厌 2020-12-18 08:50

I am using Linq-To-Entities to do a query which is returning only 947 rows but taking 18 seconds to run. I have done a \"ToTraceString\" to get the underlying sql out and ra

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 09:45

    @Craig I couldn't get your query to work as I get an error message saying Type Inference failed in the call to SelectMany.

    However I took your advice and went from using the join to an "olde style" pre ANSI type query:

            var query = from pe in genesisContext.People_Event_Link
                        from ev in genesisContext.Events
                        where pe.P_ID == key && pe.Event == ev
                        select ev;
    

    Which produces fairly decent sql!

提交回复
热议问题