Fluent NHibernate and composite ID with single column name

后端 未结 1 1926
执念已碎
执念已碎 2021-01-13 22:11

I\'ve crossed posted this in the FNH Google Group but here\'s the scoop:

I have a table in a legacy database that has a composite ID. Well, the PK is implied since t

1条回答
  •  -上瘾入骨i
    2021-01-13 23:00

    Figured it out. You don't need to add the reference property for the parent. Notice how the many-to-one is missing in the adjusted mapping:

    public AttachmentMap()
    {
        SchemaIs(Resources.CityworksDatabaseSchema);
        WithTable(ObjectNames.TableWorkorderAttachment);
        UseCompositeId()
            .WithKeyReference(x => x.ParentWorkorder, "WORKORDERID")
            .WithKeyProperty(x => x.FileLocation, "IMAGEPATH");
        Map(x => x.AttachedByUser, "ATTACHEDBY").WithLengthOf(100).Nullable();
        Map(x => x.AttachedOn, "DATETIMEATTACHED").Nullable();
        Map(x => x.Comments).Nullable().WithLengthOf(256);
        //References(x => x.ParentWorkorder, "WORKORDERID").FetchType.Join();
    }
    

    This results in the following HBM mapping file. The fix is to have the composite-id have a key-many-to-one line pointing back to the parent class. Now I can persist my Attachment class.

    
      
        
          
          
        
        
          
        
        
          
        
        
          
        
      
    
    

    0 讨论(0)
提交回复
热议问题