Entity Framework Performance Issue

后端 未结 2 958
情话喂你
情话喂你 2021-02-01 21:03

I am running into an interesting performance issue with Entity Framework. I am using Code First.

Here is the structure of my entities:

A Book can have many Revie

2条回答
  •  情书的邮戳
    2021-02-01 21:11

    I know this sounds lame, but have you tried the other way around, e.g.:

    var reviewsAndBooks = db.Reviews.Where(r => r.Book.BookId == id)
                           .Include(r => r.Book);
    

    I have noticed sometimes better performance from EF when you approach your queries this way (but I haven't had the time to figure out why).

提交回复
热议问题