Replies: 1 comment
-
There is no simple way to do that, at least I don't see one. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am upgrading a .NET Framework project from Automapper 4.1.1 to Automapper 10.0.0 and I am encountering a problem that I am unable to resolve.
I see that ConvertUsing and ProjectUsing have been unified, but somehow I have to be able to tell if a Mapping or a Project is being done.
I have a configuration so that it is applied generically when changing a DateTime to an int so that it transforms by calculating the number of minutes.
I need to use SqlFunctions to do the conversion but only when we are projecting, when we are mapping it must be done through a simple transformation.
How can you do this if you can now only have one ConvertUsing?
CreateMap<DateTime?, int>().ConvertUsing(x => x.HasValue ? System.Data.Entity.SqlServer.SqlFunctions.DatePart("HOUR", x.Value).Value * 60 + System.Data.Entity.SqlServer.SqlFunctions.DatePart("MINUTE", x.Value).Value : 0); CreateMap<DateTime, int>().ConvertUsing(x => System.Data.Entity.SqlServer.SqlFunctions.DatePart("HOUR", x).Value * 60 + System.Data.Entity.SqlServer.SqlFunctions.DatePart("MINUTE", x).Value); CreateMap<DateTime?, int>().ConvertUsing(x => Convert.ToInt32(x.HasValue ? x.Value.TimeOfDay.TotalMinutes : 0)); CreateMap<DateTime, int>().ConvertUsing(x => Convert.ToInt32(x.TimeOfDay.TotalMinutes));
Thank you
Beta Was this translation helpful? Give feedback.
All reactions