說我有一個這樣的類:我可以使用NHibernate以xml序列化的形式存儲對象嗎?
public class MyClass
{
public int Id { get; set; }
public DateTime Date { get; set; }
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string String4 { get; set; }
}
是否有可能得到NHibernate的將其存儲在下面的架構?
CREATE TABLE [dbo].[MyClass](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Xml] [varchar](max) NOT NULL,
)
其中Id映射到Id,但所有其他字段被序列化爲XML(或其他)?我不介意這些等領域都走像以下的兒童對象,如果這能幫助:
public class MyClass
{
public int Id { get; set; }
public AllOtherOptions Options { get; set; }
}
public class AllOtherOptions
{
public DateTime Date { get; set; }
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string String4 { get; set; }
}
聽起來像一個相當優雅的解決方案;我喜歡。 – 2009-05-01 14:42:01
我發現如果你的類型是用[Serializable]標記的,如果你添加了「type =」serializable「」到你的映射,NH會自動爲你進行二進制(de)序列化,這對我來說是工作的,謝謝你的鏈接tho +1 – 2009-05-01 17:25:36