每个子类的表映射在获取时失败

时间:2012-02-08 15:20:31

标签: fluent-nhibernate nunit

代码编译正常,但NUnit测试失败,出现以下错误:
09:59:00789 ERROR [TestRunnerThread] AbstractBatcher [(空)] - 无法执行查询:SELECT workflow0_.Id如Id13_0_,workflow0_.Name如Name13_0_,workflow0_.ModifiedById如Modified3_13_0_,workflow0_.ModifiedDate如Modified4_13_0_,workflow0_.CreatedById如CreatedB5_13_0_,workflow0_.CreatedDate如CreatedD6_13_0_,workflow0_.Version如Version13_0_,workflow0_.WorkflowTemplateID如Workflow8_13_0_,workflow0_1_.PBMId如PBMId14_0_,情况下,当workflow0_1_.Workflow_id不为空则1时workflow0_.Id不为空则结束0作为clazz_0_ FROM工作流workflow0_左外连接WorkflowRDSCostReport workflow0_1_ on workflow0_.Id = workflow0_1_.Workflow_id WHERE workflow0_.Id=@p0 System.Data.SqlClient.SqlException(0x80131904):列名称'Workflow_id'无效。

如果删除包含子类映射的文件,测试将正常运行。父级是“Id”作为PK列的工作流程。 Child是WorkflowRDSCostReport,其中“WorkflowId”为PK& 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
}

WorkflowRDSCostReport.cs:

public class WorkflowRDSCostReport : Workflow
{
    #region properties

    public virtual int PBMId { 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();
    }
}

WorkflowRDSCostReportMap.cs:

public class WorkflowRDSCostReportMap : SubclassMap<WorkflowRDSCostReport>
{
    public WorkflowRDSCostReportMap()
    {
        Table("WorkflowRDSCostReport");

        Map(x => x.PBMId, "PBMId")
            .Not.Nullable();
    }
}

WorkflowRepository.cs:

public class WorkflowRepository : RepositoryBase<Workflow, int>
{
    public WorkflowRepository() : base() { }
}

WorkflowRepositoryTest.cs:

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
}
}

0 个答案:

没有答案