2 つの POCO クラス (Account と Invoice) があり、ご覧のとおり (以下はこれらのクラスのモックアップです)、それらは再帰的です。
account プロパティが設定された請求書オブジェクトを渡し、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; }
}