Open marcocavanna opened 1 year ago
Hi!
Thanks for the thorough report! Just to check - what version of EF Core are you using?
All the best,
Steve
Hi! Currently I'm using one of the latest, but not the last, the 6.0.7.
Thanks! The error comes from the projection Expression generated by the mapper including an embedded constant array containing the valid underlying numeric enum values - a Contains() call is performed on the array with the value in the DB column to check if it's a valid enum value.
I'll have to rework the generated Expression to do things differently. Thanks for letting me know!
Hi all!
First of all, congratulations on the excellent work of this tool that I'm starting to love and use every day!
The issue I'm facing out is the following (I'm using EFCore with SQLServer): When using the
_myContext.MySet.Where(e => e.Anything == "something").Project().To<MyModel>().ToList()
I'm receiving this error:The error above won't show if I use the standard non projection api
_myContext.MySet.Where(e => e.Anything == "something").ToList().Select(e => Mapper.Map(e).ToNew<MyModel>())
.After some tests on the code I realized that this problem comes from the projection of a value of type
int
to an enum, but this happen only when usingProject().To<Something>()
and notMap(anything).ToNew<Something>()
.I'll use a "standard" Issue Template to expose my problem:
Prerequisites
Expected Behavior
I would like to be able to use the EFCore query projection feature even when the model defined on the database has a data type of type
int
that must be mapped to an enumCurrent Behavior
An error will occur while using
_myContext.MySet.Where(e => e.Anything == "something").Project().To<MyModel>().ToList()
when the Model of _myContext.MySet has a property withint
type but the MyModel has declared that property with an enum type.Failure Information (for bugs)
This problem occur only while mapping int to enum. Removing the enum property declaration (or transform type to int instead of enum) everything is working well.
Clarification
The database entities model I'm using are automatically generated using
dotate ef db scaffold
tool, then I could not change the type of the entity model described in next section at point 1, namedMyEntity
.Steps to Reproduce
Create a database entity model like
Create the DTO model (and the enum) like
class MyEntityDto { public int Id { get; set; } public string Name { get; set; } public EntityStatus Status { get; set; } }
When arriving at code described at point 3, boom, the Exception will be thrown. The issue seems to be an error while building the projection query.
Thanks for your patience reading my long issue description, I hope you arrived here and help me resolving this trouble.