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
entity-framework automapper


source to share


No one has answered this question yet

Check out similar questions:

183
The cast value for "Int32" failed because the materialized value is null
five
How do I map a nullable property to a DTO using AutoMapper?
4
AutoMapper - different ProjectUsings for null and non-null values
3
AutoMapper throws away missing map when map exists
2
Inconsistent display behavior in AutoMapper 3
1
How to map an object while editing it in ASP.Net MVC using AutoMapper
1
The cast to value type failed because the materialized value is null
0
How do I handle a null foreign key field in Entity Framework?
0
Unable to break into AutoMapper Map if TSource is Nullable <datetime>
0
AutoMapper property with TypeName starts with Tbl at Source and property starts with FK at destination



All Articles
Loading...
X
Show
Funny
Dev
Pics