Description:
Bug that comes up during a query as an exception: "Unknown column 'Project1.C1' in 'field list'".
Environment: Windows 7, x64, Visual Studio 2013, .NET 4.5, Entity Framework 6, MySQL connector 6.9.3. ( In fact this bug was first introduced in ver. 6.6.6. Previous connector 6.6.5 does not have it ). Also this problem seem to be related to the bug #72004
How to repeat:
/*
Here is the full C# source code and the content of App.config
for console application to reproduce the problem:
-------------------------------------------------------------
*/
using MySql.Data.Entity;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace MySqlConnectorTest
{
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class Parking : DbContext
{
public DbSet<Car> Cars { get; set; }
public Parking(DbConnection existingConnection, bool contextOwnsConnection)
: base(existingConnection, contextOwnsConnection)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Car>().MapToStoredProcedures();
}
}
public class Car
{
public int CarId { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Manufacturer { get; set; }
}
class Program
{
static void Main(string[] args)
{
string connectionString = "server=localhost;User Id=alexei;Pwd=123456;;database=TestDB";
MySqlConnectionFactory f = new MySqlConnectionFactory();
using (DbConnection connection = f.CreateConnection(connectionString))
{
using (Parking contextDB = new Parking(connection, false))
{
contextDB.Database.Delete();
contextDB.Database.CreateIfNotExists();
}
connection.Open();
try
{
using (Parking context = new Parking(connection, false))
{
List<Car> cars = new List<Car>();
cars.Add(new Car { Manufacturer = "Nissan", Model = "370Z", Year = 2012 });
cars.Add(new Car { Manufacturer = "Ford", Model = "Mustang", Year = 2013 });
cars.Add(new Car { Manufacturer = "Chevrolet", Model = "Camaro", Year = 2014 });
cars.Add(new Car { Manufacturer = "Dodge", Model = "Charger", Year = 2015 });
context.Cars.AddRange(cars);
context.SaveChanges();
//**** normal execution *******************************************************
int[] res0 = (from c in context.Cars select c.CarId).OrderBy(n => n).ToArray();
int[] res1 = (from c in context.Cars orderby c.CarId select c.CarId).ToArray();
//*****************************************************************************
//**** ERRORS. Note the cast: (long)c.CarId *********************************************
// The next line will result in exception: "Unknown column 'Project1.C1' in 'field list'"
long[] res2 = (from c in context.Cars select (long)c.CarId).OrderBy(n => n).ToArray();
// The next line will result in exception: "Unknown column 'Project1.C1' in 'field list'"
long[] res4 = (from c in context.Cars orderby c.CarId select (long)c.CarId).ToArray();
//*****************************************************************************************
}
}
catch (Exception e)
{
int k = 0;
}
}
}
}
}
/*
//Here is the content of App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
*/
Suggested fix:
Fix the sql query formatting