Entity Framework Core count does not have optimal performance

前端 未结 9 1537
故里飘歌
故里飘歌 2020-12-20 12:19

I need to get the amount of records with a certain filter.

Theoretically this instruction:

_dbContext.People.Count (w => w.Type == 1);
         


        
9条回答
  •  一生所求
    2020-12-20 12:43

    It seems that there has been some problem with one of the early releases of Entity Framework Core. Unfortunately you have not specified exact version so I am not able to dig into EF source code to tell what exactly has gone wrong.

    To test this scenario, I have installed the latest EF Core package and managed to get correct result.

    Here is my test program:

    And here is SQL what gets generated captured by SQL Server Profiler:

    As you can see it matches all the expectations.

    Here is the excerpt from packages.config file:

    ...
    
    ...
    

    So, in your situation the only solution is to update to the latest package which is 1.1.0 at the time of writing this.

提交回复
热议问题