简体   繁体   English

C# Entityframework core 2.1 查询不包括 where 条件

[英]C# Entityframework core 2.1 query not including where condition

My following query is not including the where condition in sql query plan.我的以下查询不包括 sql 查询计划中的 where 条件。

var userStandby = await _context.UserStandby
                                .FirstOrDefaultAsync(standBy => ECUserId.Equals(standBy.ECUserId, StringComparison.OrdinalIgnoreCase));

i am using EF Core 2.1 and the UserStandby table has got 12500 records.我正在使用 EF Core 2.1,并且 UserStandby 表有 12500 条记录。 I am getting timeout error as the query is not including the where condition.我收到超时错误,因为查询不包括 where 条件。

Can anyone please help me how to resolve this?谁能帮我解决这个问题?

thanks谢谢

Try this instead试试这个

var userStandby = await _context.UserStandby
                                .Where(standBy => ECUserId.Equals(standBy.ECUserId, StringComparison.OrdinalIgnoreCase))
                                .FirstOrDefaultAsync();

You put your condition in the Where expression and with firstordefault you say that you want only 1 result or null.您将条件放在 Where 表达式中,并使用 firstordefault 表示您只需要 1 个结果或 null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM