Support for querying props with valid nullability variation #136
-
Example scenario: record class Product (int Id, int? Price);
record class PricedProductModel (int Id, int Price);
CreateMap<Product, PricedProductModel>(); These work: IMapper.Map<Product, PricedProductModel>();
DbContext.Set<Product>().ProjectTo<PricedProductModel>(...); This doesn't, and the error is a little confusing (but I understand why it exists): DbContext.GetQuery<Product>().GetQueryAsync<PricedProductModel>(...); Gives an error that types must match, but the message is a little confusing because the source and destination are the reverse of the only developer-declared CreateMap call:
I think this is a known unsupported scenario, so I didn't push it up as an issue, but I'm wondering if anyone has a workaround like manually setting up another expression to get used in this scenario, or some info on which library a PR would belong in. Right now I was trying to hack some expression conversion into the ForAllPropertyMaps on an app because it's migrating from v9 to v11 and a lot of the OData queries stopped working, but it is getting generic-call reflection heavy so I'd rather just find a real solution or document a workaround if a PR would be accepted. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You'll need custom expressions when the types are not an exact match e.g. CreateMap<Product, PricedProductModel>()
.ForMember(dest => dest.Price, opts => opts.MapFrom(x => x.Price.Value)); or for constructor maps: CreateMap<Product, PricedProductModel>()
.ForCtorParam("Price", opts => opts.MapFrom(x => x.Price.Value)); If custom expressions don't work then open an issue with sample reproducing the error. |
Beta Was this translation helpful? Give feedback.
You'll need custom expressions when the types are not an exact match e.g.
or for constructor maps:
If custom expressions don't work then open an issue with sample reproducing the error.