AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Enums mapping not work in GetQuery #181

Closed petrkasnal closed 1 year ago

petrkasnal commented 1 year ago

Hi,

i use odata automapper extension.

var items = (_repository.GetAll().GetQuery(_mapper, request.Query)).ToList(); Everything working fine, but when i add enum to source and destination it not working. I give this error. I have Mapper on enums.

'Unable to create a map expression from Bom.CheckStateType (System.Nullable1[StateType]) to Nullable1.StateType (System.Nullable`1[StateType])'

BlaiseD commented 1 year ago

A sample reproducing the error would help.

Testing your configuration against ProjectTo without this library - may reproduce the same error.

petrkasnal commented 1 year ago

A sample reproducing the error would help.

Testing your configuration against ProjectTo without this library - may reproduce the same error.

Thank you for your fast response. I tried ProjectTo and the problem is the same. And I think I even found out what it is. If both fields are not null enum, everything works as it should. But if both are nullable, there is a problem. But if I use mapper.Map the normal way, the nullable fields work. It even works if I have one mandatory and the other nullable.

BlaiseD commented 1 year ago

You're probably missing a ForMember in your config telling it how the conversion should work. Otherwise I would first reference the main project and pinpoint the cause. Then create a new issue if it looks like a bug - and post the repro.