Bug #91902 DbContext.Database.SqlQuery runtime exception with Connector/NET 8.0.*
Submitted: 6 Aug 2018 2:11 Modified: 29 Jun 2019 0:42
Reporter: ncoda harmless Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.12.0 OS:Windows (10)
Assigned to: CPU Architecture:Any
Tags: DbContext, SqlQuery

[6 Aug 2018 2:11] ncoda harmless
Description:
When using .NET Connector version 8, calling SqlQuery gets an error 

System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types.'

This worked on prior versions of the connector (Currently using version 6.8.3.0).

This can be reproduced targeting at least MySQL Server versions 5.5,5.6 and 8.0

How to repeat:
//Here is an example simple .NET console program to reproduce the error

using MySql.Data.MySqlClient;
using System;
using System.Data.Common;
using System.Data.Entity;
using System.Linq;

 class Program
   {
      static void Main(string[] args)
      {
         using (MySqlConnection cn = new MySqlConnection("Server=localhost;Database=test;Uid=root;Pwd=;SslMode=none"))
         {
            cn.Open();
            using (var dbContext = new TestContext(cn, false))
            {
               long x = dbContext.Database.SqlQuery<long>("SELECT 1").Single();
               Console.WriteLine(x);
            }
         }
      }
   }

// for prior connector version: 
// [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]   [DbConfigurationType(typeof(MySql.Data.EntityFramework.MySqlEFConfiguration))]
   class TestContext : DbContext
   {
      public TestContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection)
      {
      }
   }
[9 Aug 2018 1:48] ncoda harmless
NOTE: This is using EntityFramework version 6.1.1
[29 Jun 2019 0:42] Roberto Ezequiel Garcia Ballesteros
Posted by developer:
 
The fix was done in the EntityFramework6 code since 6.1.2 version.