1
//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”时,为什么 NHibernate 会生成列名“Url_id”?

4

1 回答 1

3

您需要在映射中定义KeyColumn()列。HasMany

它应该与您在References()侧面 ( "Url") 上写的内容相匹配。

于 2012-05-26T22:57:00.173 回答