c# - 缓存列表 <T> 返回空值

标签 c# redis .net-4.5

如果我缓存 List<string>并执行 Get 我得到了四个项目及其值(如预期)。如果我缓存 List<PortedNumberCollection>并执行 Get- 我得到了正确数量的项目,但所有值(MSISDN、RoutingLabel、RouteAction)都为空,为什么?

[DataContract]
public class PortedNumberCollection
{
    [DataMember]        
    public Int64 PortedID;

    [DataMember]        
    public string MSISDN;

    [DataMember]        
    public string RoutingLabel;

    [DataMember]
    public string RouteAction;
}

string host = "localhost";

RedisClient redi = new RedisClient(host);

//List<string> PorCol = new List<string> {
//    "Hi there",
//    "Hello world",
//    "Many name is",
//    "Uh, my name is"
//};

List<PortedNumberCollection> PorCol = MobileDAL.ReadPortedNumberCollection();
redi.Set("PorColCache", PorCol);

//List<string> msgs = redi.Get<List<string>>("PorColCache");
List<PortedNumberCollection> msgs = redi.Get<List<PortedNumberCollection>>("PorColCache");

最佳答案

您可以尝试添加 {get;设置;} 在字段之后?像 public string RouteAction {get;设置;

关于c# - 缓存列表 <T> 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20223033/

相关文章:

.net - 不允许从网络位置加载程序集

MySQL - 如何在使用多个过滤器查询时保持可接受的响应时间(我应该使用 Redis 吗?)

c# - 遍历 List<T> 时出现空引用异常

c# - MVC 2 - 标签的数据注释?

c# - 结合两个正则表达式进行 ASP.NET MVC 数据注释

c# - 如何在 SDK V3 上对 Cosmos-db 查询异步运行 LINQ Count

c# - 从 Base 继承的基类属性

concurrency - Redis INCR 并发

Python redis 发布订阅 : what happen to types when it gets published?

c# - Array.Copy --> 不支持大于 2GB 的数组