我有两个 POCO 类(Account 和 Invoice),如您所见(下面是这些类的模型),它们是递归的。
当我传入带有帐户属性集的发票对象,然后尝试使用 redis 客户端存储它时,它会由于递归而导致堆栈溢出。下面是我如何拨打电话的示例。
CachingService.Store<Invoice>(invoiceObj);
public class CachingService {
// ....
public static void Store<T>(T obj)
{
using (var client = _redisClientsManager.GetClient())
{
var typedClient = client.GetTypedClient<T>();
typedClient.Store(obj);
}
}
}
我的 POCO 课程示例:
public class Account
{
public string Name { set; get; }
public bool IsActive { set; get; }
public virtual ICollection<Invoice> Invoices { set; get; }
}
public class Invoice
{
public bool IsPaid { set; get; }
public DateTime? LastSent { set; get; }
public int AccountId { set; get; }
public virtual Account Account { set; get; }
}