简体   繁体   English

使用Entity Framework 6检查Oracle数据库中是否存在记录的最快方法

[英]Fastest way to check if a record exists in an Oracle Database with Entity Framework 6

I need to figure out if a key exists in an Oracle database using Entity Framework. 我需要确定使用实体框架在Oracle数据库中是否存在密钥。 My front end uses this call a lot, I was wondering which approach would be fastest? 我的前端经常使用此调用,我想知道哪种方法最快? Should I get the first matching record and check if is null, check the count of the key and see if it's greater than one, or use Any? 我应该获取第一个匹配记录并检查是否为空,检查键的计数并查看其是否大于一个,或使用Any吗? Or is there a solution I haven't thought of that is quicker than these? 还是有一个我没有想到过的解决方案比这些解决方案更快?

I'd recommend Any , as you don't need to count. 我建议使用Any ,因为您无需计数。 It should be translated to an EXISTS statement, which is faster than a COUNT(*). 应该将其转换为EXISTS语句,该语句比COUNT(*)更快。

Maybe something like: 也许像:

var exists = ctx.MyEntities.Where(x => x.Id == ...).Any();

Don't instantiate your entity (eg, using Find ) because that would hurt the performance, as you only want to check if a record exists. 不要实例化您的实体(例如,使用Find ),因为那样会损害性能,因为您只想检查记录是否存在。

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

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