NHibernate:为什么我的探查器查询不符合我的流畅映射?

时间:2010-01-05 21:12:16

标签: nhibernate fluent-nhibernate

我有这种流畅的映射:

sealed class WorkPostClassMap : ClassMap<WorkPost>
{
    public WorkPostClassMap()
    {
        Not.LazyLoad();

        Id(post => post.Id).GeneratedBy.Identity().UnsavedValue(0);
        Map(post => post.WorkDone);
        References(post => post.Item).Column("workItemId").Not.Nullable();
        References(Reveal.Property<WorkPost, WorkPostSheet>("Owner"), "sheetId").Not.Nullable();
    }

父类:

sealed class WorkPostSheetClassMap : ClassMap<WorkPostSheet>
{
    public WorkPostSheetClassMap()
    {
        Id(sheet => sheet.Id).GeneratedBy.Identity().UnsavedValue(0);
        Component(sheet => sheet.Period, period =>
                                             {
                                                 period.Map(p => p.From, "PeriodFrom");
                                                 period.Map(p => p.To, "PeriodTo");
                                             });
        References(sheet => sheet.Owner, "userId").Not.Nullable();
        HasMany(sheet => sheet.WorkPosts).KeyColumn("sheetId").AsList();
    }

WorkItem类:

sealed class WorkItemClassMap : ClassMap<WorkItem>
{
    public WorkItemClassMap()
    {
        Not.LazyLoad();

        Id(wi => wi.Id).GeneratedBy.Assigned();
        Map(wi => wi.Description).Length(500);
        Version(wi => wi.LastChanged).UnsavedValue(new DateTime().ToString());
    }
}

当从拥有的工作帖子表中延迟加载一组WorkPosts时,我得到以下select语句:

SELECT  workposts0_.sheetId as sheetId2_, 
        workposts0_.Id as Id2_, 
        workposts0_.idx as idx2_, 
        workposts0_.Id as Id2_1_, 
        workposts0_.WorkDone as WorkDone2_1_, 
        workposts0_.workItemId as workItemId2_1_, 
        workposts0_.sheetId as sheetId2_1_, 
        workitem1_.Id as Id1_0_, 
        workitem1_.LastChanged as LastChan2_1_0_, 
        workitem1_.Description as Descript3_1_0_ 

FROM    "WorkPost" workposts0_ 
        inner join "WorkItem" workitem1_ on workposts0_.workItemId=workitem1_.Id 

WHERE   workposts0_.sheetId=@p0;@p0 = 1

不,这里有一些事情对我没有意义:

  1. 工作路标“Id”属性在select语句中出现两次
  2. 有一个选择引用名为“idx”的列,但该列不是任何流畅映射的一部分。
  3. 任何能帮助解释这个问题的人都会有所帮助吗?

1 个答案:

答案 0 :(得分:1)

idx列位于选择列表中,因为您已将Sheet.WorkPosts映射为有序列表。需要idx列来设置列表中的项目顺序。我不确定为什么id属性在select语句中两次。

顺便说一下,未保存的值0是标识字段的默认值,因此如果需要,可以删除.UnsavedValue(0)