【发布时间】:2013-07-23 19:39:48
【问题描述】:
这很奇怪,因为无法将 DataCacheItem 投射到列表集合。
我正在从数据库中提取值并将其存储到缓存中,但如果我要求缓存使用 TypeCast 返回数据,那么它拒绝这样做。
Cannot cast 'isValueInCache' (which has an actual type of
'Microsoft.ApplicationServer.Caching.DataCacheItem') to
'System.Collections.Generic.List<MMD.Data.HumanGender>'
//Setting Value in Cache Object
var isValueInCache = BaseCache.Instance().RetrieveCacheValue("allGenders");
//TypeCasting of Data
var isSeariled = isValueInCache == null ?
Newtonsoft.Json.JsonConvert.DeserializeObject(proxy.GetAllGenders(),
typeof(List<HumanGender>)) as List<HumanGender>
: isValueInCache as List<HumanGender>;
我还没有发现为什么它不能将Object 转换为List<T>。我似乎只在这里工作,以JSON 格式投射对象,按键拉动并创建List Object。
更新 1:
这种情况不仅适用于列表,还适用于从缓存中检索到的任何实体对象。
更新 2:
也不使用 DTO。
仍在寻找解决办法。
【问题讨论】:
标签: c#-4.0 azure collections entity-framework-5 azure-caching