Where is the offer at Fluent NHibernate Many-to-Many

I'm trying to set up a many-to-many mapping in Fluent Nhibernate, which has a where clause attached to a 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 assumes that it is part of the ProductImages table. Any idea how I can point this out?

Thanks!

+4
source share
2 answers

You cannot, as far as I know. I'm not sure where is valid on many-to-many associations.

I would handle this by creating an extension method on IEnumerable<Image> to make it easier to filter by image type. Then you can call Images.Landscape (), for example, in any collection of images.

0
source

You can. Use .ChildWhere in your Fluent NHibernate:

 HasManyToMany(p => p.Images) .Table("ProductImages") .ParentKeyColumn("ProductID") .ChildKeyColumn("ImageID") .ChildWhere("ImageTypeID = 2"); 
+10
source

Source: https://habr.com/ru/post/1300889/


All Articles