This is a very complex problem in F #, which is extremely simple in C #
I am using a custom DomainManager to write the Azure Mobile application table controller in F #. DomainManager inherits from MappedEntityDomainManager<,> , which uses Automapper under covers to map my database objects to mobile reports.
The Automapper profile is as follows:
type EventOrganiserProfile() = inherit Profile() do let nullDateTime = Nullable<DateTime>() base.CreateMap<MyDbEntity, MyMobileDto>() ... .ForMember(fun dest -> dest.UpdatedAt, fun opt -> opt.MapFrom(fun src -> if src.CancelledUtc <> nullDateTime then src.CancelledUtc.Value else src.StartedUtc)) ... |> ignore base.CreateMap<MyMobileDto, MyDbEntity>() ... |> ignore
src.StartedUtc is a DateTime , src.CancelledUtc is a valid DateTime , and since its class inherits from EntityData , dest.UpdatedAt is a valid DateTimeOffset .
This code compiles, but when I try to run it, I get an error
System.NotSupportedException: "LINQ to Entities does not recognize the method 'System.DateTime Invoke (System.Nullable`1 [System.DateTime])' method, and this method cannot be translated into a storage expression. '
This seems to apply to my use of the .Value Nullable<DateTime> property. The main reason is strict type checking F #. In C #, would this be easily handled by a null coalescing operator ?? .
Is there a way to simulate zero coalescence as part of an Entity Framework-friendly expression in F #?
f # entity-framework
Rob lyndon
source share