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:
Category:Connector / NET Severity:S1 (Critical)
Version: OS:Windows (10)
Assigned to: CPU Architecture:Any
Tags: DbContext, SqlQuery

[6 Aug 2018 2:11] ncoda harmless
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

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"))
            using (var dbContext = new TestContext(cn, false))
               long x = dbContext.Database.SqlQuery<long>("SELECT 1").Single();

// 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.