jer*_*ome 2 c# nhibernate nhibernate-mapping fluent-nhibernate fluent-nhibernate-mapping
我有一个带有IList<string>属性的简单类.如何在Fluent Nhibernate中映射此房源?
[Serializable]
public class ExportTask
{
private IList<string> _csvExportList = new List<string>();
public ExportTask()
{}
public virtual IList<string> CsvExportList
{
get { return _csvExportList; }
set { _csvExportList = value; }
}
}
public class ExportTaskMap : SubclassMap<ExportTask>
{
public ExportTaskMap()
{
HasMany(x => x.CsvExportList)
.Element("CsvExportList")
.Cascade
.AllDeleteOrphan();
}
}
Run Code Online (Sandbox Code Playgroud)
发生以下错误:
Initializing -failed to lazily initialize a collection of role: MyApp.Tasks.ExportTask.CsvExportList, no session or session was closed
Run Code Online (Sandbox Code Playgroud)
在集合上调用addrange时:
var exportList = new List<string>()
{
{"item1"},
{"item2"}
};
CsvExportList.AddRange(exportList);
Run Code Online (Sandbox Code Playgroud)
事实证明,我们可以使用AsList列的列表索引和allworks的映射.我想知道为什么这个简单的用例没有答案.希望它有助于某人.
public class ExportTaskMap : SubclassMap<ExportTask>
{
public ExportTaskMap()
{
HasMany(x => x.CsvExportList)
.Element(@"CsvProperty")
.KeyColumn(@"ExportTask_id")
.Table(@"CsvExportProperties")
.AsList(x => x.Column(@"CsvPropertyListIndex"))
.Not.LazyLoad();
}
}
Run Code Online (Sandbox Code Playgroud)
映射表在数据库中看起来如下所示.
