Fluent NHibernate mapping on multiple non-PK fields

后端 未结 1 1576
甜味超标
甜味超标 2021-02-10 01:00

I have a situation similar to that described in Fluent NHibernate Mapping not on PK Field

However, the relationship between my tables is described by multiple non-primar

1条回答
  •  我在风中等你
    2021-02-10 01:18

    using hbm.xml and FluentNHibernate it is possible with a trick

    class PersonMap : ClassMap
    {
        public PersonMap()
        {
            Map(_ => JobTypeAndCode)
                .Columns.Add("Person_JobType", "Person_Code")
                .ReadOnly()
                .LazyLoad() // optional: prevent loading the Columns twice
                .Access.None();
    
            HasMany(p => p.Orders)
                .KeyColumns.Add("Person_JobType", "Person_Code")
                .PropertyRef("JobTypeAndCode")
        }
    
        private object JobTypeAndCode { get; set; } // FakeProperty
    }
    

    Note: i never got this to work using NHibernate MappingByCode

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