Fluent nhibernate 每个子类的表映射在获取时失败
代码编译良好,但NUnit测试失败,出现以下错误:Fluent nhibernate 每个子类的表映射在获取时失败,fluent-nhibernate,nunit,Fluent Nhibernate,Nunit,代码编译良好,但NUnit测试失败,出现以下错误: 09:59:00789错误[TestRunnerThread]AbstractBatcher[(null)]-无法执行查询:选择workflow0.Id作为Id13\u 0,workflow0.Name作为Name13\u 0,workflow0.ModifiedById作为Modified3\u 13\u 0,workflow0.ModifiedDate作为Modified4\u 13\u 0,workflow0\u0.CreatedById
09:59:00789错误[TestRunnerThread]AbstractBatcher[(null)]-无法执行查询:选择workflow0.Id作为Id13\u 0,workflow0.Name作为Name13\u 0,workflow0.ModifiedById作为Modified3\u 13\u 0,workflow0.ModifiedDate作为Modified4\u 13\u 0,workflow0\u0.CreatedById作为CreatedB5\u 13\u 0,workflow0.CreatedDate作为CreatedD6\u 13\u 0,workflow0.Version作为Version13\u 0\u,workflow0\u.WorkflowTemplateID作为Workflow8\u 13\u 0\u,workflow0\u 1\u.PBMId作为PBMId14\u 0\u,当workflow0_1_.Workflow_id不为null时的情况,然后当workflow0_.id不为null时的情况,然后从workflow0_结束为clazz_0_工作流0左外部联接WorkflowRDSCostReport workflow0_1_在workflow0上。id=workflow0_1_.Workflow_id,其中workflow0_.id=@p0 System.Data.SqlClient.SqlException(0x80131904):列名“Workflow_id”无效 如果我删除包含子类映射的文件,测试将正常运行。父工作流以“Id”作为主键列。子项是WorkflowRDSCstreport,其中“WorkflowId”作为主键和FK关系。WorkflowTemplate是一个单独的表,可以正常工作。代码: Workflow.cs:
public class Workflow: EditableEntityBase<int>
{
#region properties
public virtual WorkflowTemplate WorkflowTemplate { get; set; }
public virtual string Name { get; set; }
#endregion properties
}
WorkflowMap.cs:
public class WorkflowMap: ClassMap<Workflow>
{
public WorkflowMap()
{
Table("Workflow");
Id(x => x.Id, "Id")
.GeneratedBy.Identity();
References(x => x.WorkflowTemplate, "WorkflowTemplateID")
.Not.Nullable()
.Not.LazyLoad()
.Cascade.None();
//Name
Map(x => x.Name, "Name")
.Nullable();
//ModifiedById
Map(x => x.ModifiedById, "ModifiedById")
.Not.Nullable();
//ModifiedDate
Map(x => x.ModifiedDate, "ModifiedDate")
.CustomType(typeof(DateTime))
.Not.Nullable();
//CreatedById
Map(x => x.CreatedById, "CreatedById")
.Not.Nullable();
//CreatedDate
Map(x => x.CreatedDate, "CreatedDate")
.CustomType(typeof(DateTime))
.Not.Nullable();
//Version
Map(x => x.Version, "Version")
.Not.Nullable();
}
}
public class WorkflowMap: ClassMap<Workflow>
{
public WorkflowMap()
{
Table("Workflow");
Id(x => x.Id, "Id")
.GeneratedBy.Identity();
References(x => x.WorkflowTemplate, "WorkflowTemplateID")
.Not.Nullable()
.Not.LazyLoad()
.Cascade.None();
//Name
Map(x => x.Name, "Name")
.Nullable();
//ModifiedById
Map(x => x.ModifiedById, "ModifiedById")
.Not.Nullable();
//ModifiedDate
Map(x => x.ModifiedDate, "ModifiedDate")
.CustomType(typeof(DateTime))
.Not.Nullable();
//CreatedById
Map(x => x.CreatedById, "CreatedById")
.Not.Nullable();
//CreatedDate
Map(x => x.CreatedDate, "CreatedDate")
.CustomType(typeof(DateTime))
.Not.Nullable();
//Version
Map(x => x.Version, "Version")
.Not.Nullable();
}
}
public class WorkflowRDSCostReportMap : SubclassMap<WorkflowRDSCostReport>
{
public WorkflowRDSCostReportMap()
{
Table("WorkflowRDSCostReport");
Map(x => x.PBMId, "PBMId")
.Not.Nullable();
}
}
public class WorkflowRepository : RepositoryBase<Workflow, int>
{
public WorkflowRepository() : base() { }
}
namespace Test
{
[TestFixture]
public class WorkflowRepositoryTest
{
#region Class Members
private Workflow _workflow;
private WorkflowRepository _workflowRepository;
private WorkflowTemplate _workflowTemplate;
private WorkflowTemplateRepository _workflowTemplateRepository;
private WorkflowRDSCostReport _workflowRDSCostReport;
#endregion Class Members
#region Setup
[TestFixtureSetUp]
public void TestFixtureSetup()
{
RepositoryBase.UseDevDatabase = true;
_workflowTemplate = TestHelper.CreateWorkflowTemplate();
_workflowTemplateRepository = new WorkflowTemplateRepository();
_workflowTemplateRepository.Save(_workflowTemplate);
}
[SetUp]
public void SetUp()
{
_workflow = TestHelper.CreateWorkflow(_workflowTemplate);
_workflowRepository = new WorkflowRepository();
_workflowRDSCostReport = TestHelper.CreateWorkflowRDSCostReport();
}
#endregion Setup
[Test]
public void DeleteTest()
{
_workflowRepository.Save(_workflow);
Workflow readEntity = _workflowRepository.Fetch(_workflow.Id);
Assert.NotNull(readEntity);
_workflowRepository.Delete(_workflow);
readEntity = _workflowRepository.Fetch(_workflow.Id);
Assert.IsNull(readEntity);
_workflow = null;
}
#region TearDown
[TearDown]
public void TearDown()
{
if (_workflow != null)
{
_workflowRepository.Delete(_workflow);
}
if (_workflowRDSCostReport != null)
{
_workflowRepository.Delete(_workflowRDSCostReport);
}
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
_workflowTemplateRepository.Delete(_workflowTemplate);
}
#endregion // TearDown
}
}