Bug #72148 EF6 + View + Take = Every derived table must have its own alias
Submitted: 27 Mar 2014 21:40 Modified: 17 Oct 2014 3:49
Reporter: Natan Vivo Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.8.3 OS:Any
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any

[27 Mar 2014 21:40] Natan Vivo
Description:
When trying to select from a view using EF 6.1 and .NET connector 6.8.3, if you use "Take" to limit the results, the generated sql is invalid.

How to repeat:
1. Create a new project
2. Add EF6 and Mysql connector 
3. Add an EDMX and import any view from a database
4. Try to select with "context.view_name.Take(10).ToList()"

The generated SQL looks like this:
"SELECT field FROM (SELECT field FROM view_name) LIMIT 10"

which gives an error because the derived table does not have an alias.

Suggested fix:
Add an alias to the SQL if selecting from a view.
[9 Oct 2014 16:38] Fernando Gonzalez.Sanchez
Posted by developer:
 
With the fix, LINQ to Entities queries that use Views and Take operator are correctly generated (this problem affected Entity Framework Database First scenarios).

This fix will appear in Connector/NET versions 6.7.6, 6.8.4 & 6.9.5.
[17 Oct 2014 3:49] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 6.7.6 / 6.8.4 / 6.9.5 release, and here's the changelog entry:

"LINQ to Entities" queries that used Views with the "Take" operator were
not correctly generated. This problem affected EF "Database First"
scenarios.

Thank you for the bug report.