我有,我想在RavenDB使用爲一個文件鍵的一類:如何使用引用類型作爲關鍵文件在RavenDB
public class DocumentKey
{
public string Namespace { get; set; }
public string Id { get; set; }
}
我還實施了ITypeConverter
(不.NET之一,RavenDB特定的一個)接口將參考類型轉換爲字符串(因爲在數據庫中,the keys are all really just strings)。
最後,我已將ITypeConverter
的實現添加到IDocumentStore
實現中,通過List<ITypeConverter>
通過Conventions.IdentityProviders
屬性公開。
然而,在IAsyncDocumentSession
實施LoadAsync<T>
重載簽名看起來像這樣(去除其中需要多個ID爲簡潔的簽名此外,同爲Load
的IDocumentSession
接口上。):
LoadAsync<T>(string id);
LoadAsync<T>(ValueType id);
我真的不想爲我的密鑰使用值類型,原因如下:
- 我有一個抽象,它對鍵的類型沒有約束。創建單獨的結構來鏡像這只是具有值類型非常不方便。
- 由於被限制爲值類型,我無法完全控制該類型。值類型有一個默認構造函數,它以我不想在代碼中的其他任何地方處理的方式默認值。
如何在RavenDB中使用引用類型作爲文檔鍵?