views:

33

answers:

1

I have this fluent mapping:

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();
    }

parent class:

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 class:

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());
    }
}

And when a collection of WorkPosts are lazy loaded from the owning work post sheet I get the following select statement:

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

No, there are a couple of things here which doesn't make sence to me:

  1. The workpost "Id" property occurs twice in the select statement
  2. There is a select refering to a column named "idx" but that column is not a part of any fluent mapping.

Anyone who can help shed some light on this?

+1  A: 

The idx column is in the select list because you have mapped Sheet.WorkPosts as an ordered list. The idx column is required to set the item order in the list. I'm not sure why the id property is in the select statement twice.

By the way, an unsaved value of 0 is the default for identity fields, so you can remove .UnsavedValue(0) if you want.

Jamie Ide