Fluent NHibernate中的Where子句多对多

Ada*_*cht 4 .net c# nhibernate orm fluent-nhibernate

我试图在Fluent Nhibernate中设置一个多对多映射,其中where子句附加到子表.

这基本上是它应该如何工作:

HasManyToMany(p => p.Images)
  .Table("ProductImages")
  .ParentKeyColumn("ProductID")
  .ChildKeyColumn("ImageID")
  .Where("ImageTypeID = 2");
Run Code Online (Sandbox Code Playgroud)

ImageTypeID列位于Images表中,但NHibernate假设它是ProductImages表的一部分.知道如何指定这个吗?

谢谢!

aut*_*att 10

您可以.在Fluent NHibernate映射中使用.ChildWhere:

HasManyToMany(p => p.Images)
  .Table("ProductImages")
  .ParentKeyColumn("ProductID")
  .ChildKeyColumn("ImageID")
  .ChildWhere("ImageTypeID = 2");
Run Code Online (Sandbox Code Playgroud)