Rob*_*don 7 f# entity-framework
这是F#中一个极其困难的问题,在C#中非常容易
我正在使用自定义DomainManager在F#中编写Azure移动应用程序表控制器.该DomainManager所继承MappedEntityDomainManager<,>,它采用Automapper在幕后来映射我的数据库对象转换成适合移动设备的记录.
Automapper配置文件如下所示:
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
Run Code Online (Sandbox Code Playgroud)
src.StartedUtc是一个DateTime,src.CancelledUtc是一个可空的DateTime,因为它的类继承自的EntityData,dest.UpdatedAt是一个可空的DateTimeOffset.
此代码编译,但当我尝试运行它时,我收到错误消息
System.NotSupportedException:'LINQ to Entities无法识别方法'System.DateTime Invoke(System.Nullable`1 [System.DateTime])'方法,并且此方法无法转换为商店表达式.
这似乎指的是我对.Value财产的使用Nullable<DateTime>.根本原因是F#严格的类型检查.在C#中,这将由空合并运算符无缝处理??.
有没有办法模拟空合并作为F#中实体框架友好表达式的一部分?
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |