Nullable collections in queryable projection mappings cannot be translated by EF Core
Mapperly adds non-null conditions when mapping properties if the property is nullable or in a disabled nullability context. If this happens inside a queryable projection mapping, EF Core is not able to translate these non-null assertions for navigational collection properties. Mapperly should special-case this and not generate the not-null condition on collection properties inside queryable projection mappings.
Brought up by @Seszele in https://github.com/riok/mapperly/discussions/855
For me, I think null check on source target properties should be enabled. It will help in cases when Child Collections are not included in Entities.
This would also be EF Core specific, although IQueryable may be used by other components... Need to think about this, we probably need to have a configuration which ensures EF Core compatibility for IQueryable projection mappings. Even then it would be quite hard to find out at compile time whether a given collection/property is included in the EF Core model.
It would be hard, But that's why devs are looking for "Mapperly"
Hi, is there any development on this issue? I am struggling with this problem and I hope it will be solved soon :)
No there are no news on this one.
May I know why do you use nullable collection properties?
According to MS (https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types):
Collection navigations, which contain references to multiple related entities, should always be non-nullable. An empty collection means that no related entities exist, but the list itself should never be null.
Also see https://github.com/dotnet/efcore/issues/29892. Here the conclusion is they usually should not be null, although there are some rare cases where nullable collections make sense. I'm interested in what your use-case actually is.
Closing for now as no further feedback is provided.