Search code examples
entity-frameworkany

Entity Framework 4 Any()


Basically I have a query where I need to check to see if the data exists on another table.

 bool isInUse;
 IsInUse = entity.H83SAF_HEALTH_PLAN.H83SAF_CONSENT.Any();

When I used clutch to trap the query to see what was going on, I could see the query running basically like this:

 SELECT 
 "Extent1"."ACTIVE" AS "ACTIVE", 
 "Extent1"."IS_COMPLETE" AS "IS_COMPLETE", 
 "Extent1"."DATE_CREATED" AS "DATE_CREATED", 
 "Extent1"."DATE_MODIFIED" AS "DATE_MODIFIED", 
 "Extent1"."CREATED_BY" AS "CREATED_BY", 
 "Extent1"."MODIFIED_BY" AS "MODIFIED_BY"
  ...more columns..natter, natter..
 FROM "H83FTF"."H83SAF_CONSENT" "Extent1"
 WHERE ("Extent1"."HEALTH_PLAN_ID" = 1)

The query itself is fine. I have a problem with the .Any() statement. What I thought should happen is that the query should quit abruptly when the .Any() condition is met.

Yet when the query I run, it looks like like the query is bringing back over 18,000 records (which I don't use) I only want to see if the data exists on the other table if the condition is met - as it is, the query hangs up the website while 18,000 rows are executed with the .Any() statement.

The first row has the condition met but my understanding is that .Any() should quit or stop the moment the condition is met.

I tried firstordefault() yet it still fetches 18000 rows in the memory...


Solution

  • Finally came to a conclusion is that using .Any() on EF 5.0 does not translate to exist in Oracle 11g - solution was to do a direct call and bring back yes or no.