Can AutoMapper handle nullable child objects in mapped original model using EF?

I used AutoMapper (3.1.1 earlier and now 3.2.1 when testing this situation) to handle mapping from EF models to disabled Business Service models. As our use expanded, I started seeing this type of error anytime we try to render an EF model with a nested complex type with a null value:

Unable to create null value for constant of type 'BusinessService.Models.TireOptions'. Only object types, enumeration types, or primitive types are supported in this context.

For this simplified example, let's say we have a ConstructionOrder class with a TireOptions member. In the relational database that EF is modeling, the ConstructionOrder table is defined with NULL-FK to the TireOption table and the corresponding FK-based NavigationProperty.

This error occurs every time we try to render via Project (). To () regardless of whether a value for TireOptions exists or not in the returned EF ConstructionOrder model. Before upgrading from 3.1.1 to 3.2.1, I saw a different error, but only when there was no data for the child TireOptions object.

The error that occurred in 3.1.1 was as follows:

Type "Int32" failed because the materialized value is null. Both the general result parameter and the query must use a nullable type.

It looks like a simple case of handling nested null complex types, but this comment from the Entity Framework Triage Team leads me to think that the expression tree generated by AutoMapper cannot be handled by EF. Is this really true, or is there work around situations like this?

+3


source to share





All Articles