Tuesday, April 5, 2011

Where clause in nhibernate map

I have an Nhibernate hbm that maps a many to many relationship. For database simplicity it uses a where clause on the bag to filter the joining table.

this works well until I start to test and I use the hbm file to create a database from the generated schema. The root and user tags columns aren't created.

In the hbm file how do I define these two columns so they are generated in the schema?

From stackoverflow
  • this works for me (sorry if you don't like attribute mapping - but I think you should get the idea). Important is specifying both columns - otherwise it included a strange column (val - something along the line - forgot the exact name) and used this instead of the ones I wanted.

    [Bag(0, Cascade = "all", Table = "item_hierarchy")]
    [Key(1, Column = "child")]
    [ManyToMany(2, ClassType = typeof(Item), Column="parent",NotFound = NotFoundMode.Ignore)]
    public virtual IList<Item> Parent { get; set; }
    

0 comments:

Post a Comment