Skip to content

NH-3095 - Cast from mapped long field to enum leads to 'Specified cast not valid' #1121

@nhibernate-bot

Description

@nhibernate-bot

Serge SB created an issue — 23rd March 2012, 7:26:54:

I have an enum:

public enum Colors
{
  Red = 1,
  Green = 2,
  Blue = 3,
}

I have table in database, that maps to:

public class SomeEntity
{
  ...
  public virtual long Id { get; set; }
  public virtual long Color { get; set; }
  ...
}

And I have an info class, that I use for work:

public class SomeInfo
{
  public long Id { get; set; }
  public Colors MyColor { get; set; }
}

When I execute this:

var result = (from item in session.Query<SomeEntity>()
  select new SomeInfo
    {
      Id = item.Id,
      MyColor = (Colors) item.Color,
    }).List();

NHibernate throws exception 'Specified cast not valid'.

But when I change the declaration of enum from this:

public enum Colors

to this:

public enum Colors : long

everything works fine.

I've encountered this issue after migrating from 2.1.2GA NHibernate with linq2nhibernate extension to current 3.2.0GA version of NHibernate. So, 2.1.2 worked fine, but 3.2.0 throws that exception.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions