Convert hbm.xml Mappings to Confirmist Code Mapping in Nhibernate

238 views Asked by At

Presently I am converting the hbm.xml files to Code Mapping (Confirmist). I am able to convert everything but I am not sure how to convert the where clause in manyToMany attribute.

<set inverse="true" name="Skills" table="UserPrivileges" mutable="true">
            <key>
                <column name="UserID" />
            </key>
            <many-to-many class="School.Campaign.Domain.Skill, School.Campaign.Domain" where="PrivilegeType = 'Skill'">
                <column name="PrivilegeID" />
            </many-to-many>
        </set>

Here when I convert like this :

Set(x => x.Skills, m =>
                {
                    m.Schema("dbo");
                    m.Table("UserPrivileges");
                    m.Key(k => k.Column("UserID"));
                    m.Cascade(Cascade.None);
                }, col => col.ManyToMany(m =>
                {
                    m.Columns(x => x.Name("PrivilegeID"));
                })
                );

But this will not work as the where clause and class type is missing. Can any one please help me out.

1

There are 1 answers

2
Andrew Whitaker On

You should be able to call .Where inside of the .ManyToMany mapping options:

Set(x => x.Skills, m =>
{
    m.Schema("dbo");
    m.Table("UserPrivileges");
    m.Key(k => k.Column("UserID"));
    m.Cascade(Cascade.None);
}, col => col.ManyToMany(m =>
{
    m.Columns(x => x.Name("PrivilegeID"));
    m.Where("PrivilegeType = 'Skill'"); // <-----
}));