views:

24

answers:

1

I have a simple EntityFramework application that accesses SQL Server 08 with a single table. I want to get a count of the rows like this:

Dim x = (From y in _Ctx.Table1).Count

Here's the SQL generated from this EF:

SELECT 
[GroupBy1].[A1] AS [C1]
FROM ( SELECT 
    COUNT(1) AS [A1]
    FROM [dbo].[Table1] AS [Extent1]
)  AS [GroupBy1]

Question: Is there a way to have EF generate simpler SQL without the subquery, e.g.

SELECT COUNT(*)
FROM Table1

Thanks in advance, david

+2  A: 

No.

And: it doesn't matter.

devio
Agreed. Although it is wordier, SQL Server doesn't care. It will parse it into the same plan. If you really like simple SQL code, don't use EF. (Just wait until you see it auto-gen complex queries!)
Strommy