是的,我在这里有另一个奇怪的问题:)
我尝试实现透明的 Redis 数据访问层。
我将加载 N*1 和 1*1 关系 Eagerly,N*N 和 1*N 关系 Lazily。
public class User
{
public long CityId {get;set;}
[EagerLoading]
[IgnoreDataMember]
public City {get;set;}
}
public class City
{
public ICollection<long> UserIds {get;set;}
[LazyLoading]
[IgnoreDataMember]
public ICollection<User> Users{get;set;}
}
CUD操作(Create,Update,Delete)没有问题。我可以存储完整的对象层次结构。
但我需要非类型化的 Get 方法来检索对象。
public class GenericRedisRepository
{
public object Get(string objectUrn)
{
using (var r = RedisManager.GetReadOnlyClient())
{
var pocoObject=r.GetObject(objectUrn); // I COULD NOT FIND THIS METHOD
foreach (var property in ReflectionHelper.GetEagerLoadingProperties(pocoObject))
{
// Fixup relations and load all EagerLoading properties recursively
}
}
}
}
任何想法或替代方式..
最佳答案
抱歉来晚了。我想知道为什么您坚持使用属性而不是本质上未序列化/反序列化的方法:
public class User
{
public long Id { get; set; }
}
public class City
{
public IEnumerable<long> UserIds { get; set; }
public IEnumerable<User> GetUsers()
{
using (var userData = redis.As<User>())
return userData.GetByIds(UserIds);
}
}
这样您就可以在真正需要用户时通过调用 GetUsers()
来延迟加载用户:
var city = redis.As<City>().GetById(id);
...
var users = city.GetUsers();
关于redis - 透明的 Redis Dal 与 serviceStack Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13522505/