Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where clause in Fluent NHibernate Many-to-Many

I am trying to setup a many-to-many mapping in Fluent Nhibernate that has a where clause attached to the child table.

This is basically how it should work:

HasManyToMany(p => p.Images)
  .Table("ProductImages")
  .ParentKeyColumn("ProductID")
  .ChildKeyColumn("ImageID")
  .Where("ImageTypeID = 2");

The ImageTypeID column is in the Images table, but NHibernate is assuming it is part of the ProductImages table. Any idea how I can specify this?

Thanks!

like image 392
Adam Albrecht Avatar asked Dec 29 '22 02:12

Adam Albrecht


1 Answers

You can. Use .ChildWhere in your Fluent NHibernate mapping:

HasManyToMany(p => p.Images)
  .Table("ProductImages")
  .ParentKeyColumn("ProductID")
  .ChildKeyColumn("ImageID")
  .ChildWhere("ImageTypeID = 2");
like image 71
autonomatt Avatar answered Jan 10 '23 01:01

autonomatt