Bug #67443 Exception on EF Select with enum and bytes

Submitted: 1 Nov 2012 7:04 Modified: 7 Dec 2012 20:11
Reporter: Andrey Veselov Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.5.4/6.6.4 OS:Windows
Assigned to: Assigned Account CPU Architecture:Any
Tags: EF, enum, SELECT

[1 Nov 2012 7:04] Andrey Veselov
Description:
Following code throws exception

The specified cast from a materialized 'System.Byte' type to the 'EnumTest.TestEnum' type is not valid.

if Enum is not Int32. Code uses EF5 under .NET 4.5. Compiled under VS2012. I try 6.5.4 and 6.6.4-RC1 - both failed.

How to repeat:
// Full source code without EDMX file. Use any with your database
namespace EnumTest
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    public enum TestEnum : byte
    {
        Value0 = 0,
        Value1 = 1,
        Value2 = 2
    }

    public class TestClass
    {
        public string Name { get; set; }
        public TestEnum Value { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable<TestClass> list;

            using (var ctx = new tennisbetsite_oncourtEntities()) {
                var c = ctx.rounds.Select(a => new TestClass {
                    Name = a.Name,
                    Value = TestEnum.Value2
                });

                list = c.ToList(); // Exception
            }
        }
    }
}

And if you replace
Value = TestEnum.Value2
by 
ValueAsByte = (byte)TestEnum.Value2
it will throw: "Exception has been thrown by the target of an invocation."

But with:

public enum TestEnum // removed ": byte"
{
    Value0 = 0,
    Value1 = 1,
    Value2 = 2
}

all works fine.

Suggested fix:
Not found. Even workaround with additional property (byte) and byte value fails with exception.
[1 Nov 2012 7:06] Andrey Veselov
BTW same code works with MSSQL so there is not a .NET/EF bug.
[7 Nov 2012 20:11] Gabriela Martinez Sanchez
Hi Andrey,

Currently our support for EF 5 and .net framework 4.5 is a work in progress (Core Entity Framework API in the .NET Framework 4 doesn't support enums). So this functionality would be completed in our next released version. If you want to know about the progress on this you can take a look on the forums where we keep posting on any news about Connector/Net (http://forums.mysql.com/list.php?38) or at our official blog (https://blogs.oracle.com/MySqlOnWindows/).

Please let us know if you have any question on this.
[8 Dec 2012 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.