//Map for Url class
this.Table("Urls");
this.Id(x => x.ID).GeneratedBy.GuidComb().Access.BackingField();
this.Map(x => x.Address).Access.BackingField();
this.HasMany(x => x.Parameters)
.Inverse()
.AsList(col => col.Column("ParameterIndex"))
.Cascade.AllDeleteOrphan()
.Access.BackingField();
//Map for UrlParameter class
this.Table("UrlParameters");
this.Id(x => x.ID).GeneratedBy.GuidComb().Access.BackingField();
this.References(x => x.Url).Column("Url").Access.BackingField();
this.Map(x => x.Name).Access.BackingField();
//Code to execute the query
Session.Query<Url>().FetchMany(x => x.Parameters);
//The SQL generated
select url0_.ID as ID1_0_, parameters1_.ID as ID2_1_, url0_.Address as Address1_0_, url0_.Prohibited as Prohibited1_0_, url0_.CreatedOn as CreatedOn1_0_, url0_.LastUpdatedOn as LastUpda5_1_0_, url0_.TotalComments as TotalCom6_1_0_, url0_.TotalNegative as TotalNeg7_1_0_, url0_.TotalNeutral as TotalNeu8_1_0_, url0_.TotalPositive as TotalPos9_1_0_, url0_.CreatedBy as CreatedBy1_0_, parameters1_.Name as Name2_1_, parameters1_.Url as Url2_1_, parameters1_.Url_id as Url4_0__, parameters1_.ID as ID0__, parameters1_.ParameterIndex as Paramete5_0__ from Urls url0_ left outer join UrlParameters parameters1_ on url0_.ID=parameters1_.Url_id where url0_.Address=@p0
//Exception message
Message=Invalid column name 'Url_id'.
为什么NHibernate在我明确告诉它在我的UrlParameter映射中使用“Url”时会生成列名“Url_id”?
答案 0 :(得分:2)
您需要在KeyColumn()
映射中定义HasMany
列。
它应该与您在References()
方("Url"
)上写的内容相匹配。