问题描述
SQLCE不支持时间跨度,所以我需要保存这个在其他一些方式。是否有可能定义一个地方默认转换,像在的DbContext,或者我需要在存储库手动处理呢?我不喜欢改变,因为这只是我的实体类。
SQLCe doesn't support TimeSpan, so I need to save this in some other way. Is it possible to define somewhere a default conversion, like in the DbContext, or would I need to handle this manually in the repositories? I don't like to change my entity classes just because of this.
顺便说一句,我只保存&LT时间跨度; 24小时。
Btw, I only save TimeSpan of < 24h.
如果有一些巧妙的技巧实例将是巨大的。
Example would be great if there are some neat tricks.
推荐答案
唉,看来这基本上是不可能的。
Well, it seems this is basically NOT POSSIBLE.
A 时间跨度
属性必须被标记 NotMapped
,或流畅忽略
(然后保存为每史蒂夫的答案)。至少这是我的理解现在。
A TimeSpan
property must be marked NotMapped
, or by fluent Ignore
(then saved as per Steve's answer).At least that's my understanding now.
EF
不支持类型映射或类型转换.. http://stackoverflow.com/a/12053328
EF
does not support type mapping or type conversion.. http://stackoverflow.com/a/12053328
顺便说一句, NHibernate的
地图时间跨度
来默认整数,在使用的SQLite
。不会进行任何转换和技巧需要在那里。不知道其他数据库。
Btw, NHibernate
maps TimeSpan
to integer by default, when using SqLite
. No conversions or tricks needed there. Not sure about other databases.
这篇关于EF,如何保存/恢复时间跨度为其他数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!