Why did the following linq to sql query generate a subquery?
Posted
by Xaisoft
on Stack Overflow
See other posts from Stack Overflow
or by Xaisoft
Published on 2009-12-14T19:45:45Z
Indexed on
2010/06/16
16:42 UTC
Read the original article
Hit count: 177
c#
|linq-to-sql
I did the following query:
var list = from book in books
where book.price > 50
select book;
list = list.Take(50);
I would expect the above to generate something like:
SELECT top 50 id, title, price, author
FROM Books
WHERE price > 50
but it generates:
SELECT
[Limit1].[C1] as [C1]
[Limit1].[id] as [Id],
[Limit1].[title] as [title],
[Limit1].[price] as [price],
[Limit1].[author]
FROM (SELECT TOP (50)
[Extent1].[id] as as [Id],
[Extent1].[title] as [title],
[Extent1].[price] as [price],
[Extent1].[author] as [author]
FROM Books as [Extent1]
WHERE [Extent1].[price] > 50
) AS [Limit1]
Why does the above linq query generate a subquery and where does the C1 come from?
© Stack Overflow or respective owner