我有兩個POCO類(Account和Invoice),正如你所看到的(下面是這些類的模型)它們是遞歸的。在StackService.Redis客戶端方法上導致stackoverflow的遞歸對象Store()
當我通過帳戶屬性設置的發票對象,然後嘗試使用redis客戶端存儲它時,它會由於遞歸而導致堆棧超載。以下是我打電話的一個例子。我的POCO類的
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);
}
}
}
例子:
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; }
}
我應該注意到,當我將ICollection更改爲IEnumerable時,問題就消失了。也許除了改變屬性類型之外,這個問題有一個實際的解決方案。 – 2012-08-11 04:24:34
你能提供你用來創建這個遞歸的方法嗎?我無法在您提供的代碼中看到它發生的情況。 – 2012-08-11 07:00:37
似乎是Redis串行器問題。 – oleksii 2012-08-11 07:52:08