c# - AutoMapper project nested objects where inner object is nullable failing -


I am using AutoMapper to project the following structure

  public class External source {... mass math? Inner Ed {Receive; Set} Public Inner Inner (Received; Set; }} Public Sector Intersource {Public Guide ID {get; Set; } Public Date Time Date {Received; Set; }} Public Class Outdoor {.... Public InnerDist Inner {get; Set; }} Public Class InDest {Public Guide ID (Receive; Set;} Public Date Time Date {Received; Set;}} Results Result = AutoMapper.Project & lt; External Asors, Outdated & gt; (Query);  

As you can see, the inner object is faucet

The projection works fine, if the value of the internal object is, but if the internal object is zero, then EF exception It throws as it does not seem to be that in inner waste Cast must be empty in value type 'guides' because the physical value is zero or the generic parameter or query type of the result should be used in the tap type. Using

  var result = AutomapMap.lt; IEnumerable & lt; External source & gt ;, IEnumerable & lt; outerDest & Gt; & gt; (query);  

Fixes my problem, but clearly I like to use the project

Is there any way around it, or I can not use it. Mapping with Nullable Inner Objects?

The problem is that your source objects are tapable fields and your destination object doesn & # 39; t work. If an asset is not faucetable and you try it and set it to free, you will get an exception. You have 2 options to fix this. Either make the field in the destination faucet

  public class external mail (public guide)? ID {Get; Set; } Public Date Time Date {Received; Set; }}  

Or create a custom handler in the mapping to handle the null and set the default value for the field in question.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -