简体   繁体   中英

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. 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? 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. It should be translated to an EXISTS statement, which is faster than a 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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