locked
EF6 CodeFirst enum mapping error: EntityCommandCompilationException (runtime) RRS feed

  • Question

  • When using a simple enum with Entity Framework 6, Code First,
    as described in that article:
    http://msdn.microsoft.com/en-us/data/hh859576.aspx

    i get the error:
    An exception of type 'System.Data.Entity.Core.EntityCommandCompilationException' occurred in mscorlib.dll but was not handled in user code
    Additional information: An error occurred while preparing the command definition.
     See the inner exception for details.
    {"The ResultType of the specified expression is not compatible with the required type.
    The expression ResultType is 'Hdi.Wizball.KfaService.Data.FunktionType' but the required type is 'Edm.Int64'.
    \r\nParameter name: keyValues[0]"}

    the code: (all available ids from the database exist here)

     public enum FunktionType : long
        {
            Element1 = 1,
            Element2 = 2,
            Element3 = 3,
            Element4 = 8,
            Element5 = 10,
            Element6 = 12
        }

         

      public partial class Geschaeftsfall
        {
            public long GeschaeftsfallId { get; set; }
    
            public DateTime? DurchfuehrungsDatum { get; set; }
    
            public FunktionType? FunktionId { get; set; }
            ....
        }

       
    if a replace the enum with a Long?, everything works,
    but i want to use the enum,..

    thanks for any help in advance,
    Thomas.


    • Edited by ThomasG Tuesday, March 18, 2014 12:17 PM
    Tuesday, March 18, 2014 12:16 PM

All replies

  • Hello ThomasG,

    Do you mean that when you use this model to create the database, it throws the error?

    If it is, could you please provide your PC environment? Because with your provided model codes, I created the database successfully:

    My environment is VS2013, .NET Framework4.5, EF 6 and SQLServer 2012.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 19, 2014 2:06 AM
  • no, database already exists and is deployed.

    The error occures when accessing the database with a simple

    context.Geschaeftsfall.ToList()

    Wednesday, March 19, 2014 7:05 AM
  • If it is possible, could you please share us with your query data, because I made a test which is using the simple query .ToList(), however, it works fine.

    My test data:

    The test result:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 20, 2014 9:06 AM