Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework SELECT 1 AS C1

OK, probably a really stupid question, but why is the query being generated by Entity Framework include "SELECT 1 AS C1" at the beginning? What is this for? For example, I have the following being generated:

SELECT 
1 AS C1, 
"Extent1".MY_ID AS MY_ID
FROM MYTABLE "Extent1"
WHERE 'test1' = "Extent1".MY_ID

If I had written this manually I would have done something like this:

SELECT 
MY_ID
FROM MYTABLE
WHERE 'test1' = MY_ID

Thanks

like image 911
Jon Archway Avatar asked Jul 14 '10 08:07

Jon Archway


1 Answers

Not all tables have a PK, unfortunately. Not all projections include a PK. The 1 as C1 allows the EF to distinguish between empty tables and selecting only nullable fields. Keep in mind this can be in a subquery or derived query, so looking at the number of rows returned doesn't necessarily answer that.

like image 165
Craig Stuntz Avatar answered Oct 19 '22 22:10

Craig Stuntz