简体   繁体   中英

Fluent NHibernate class mapping with a condition

I have a single class that contains data about two types of objects. I am not allowed to split the table in the database, so I'm just splitting them in the code. I want to do something like this:

public class MainMap : ClassMap<MainStuff>
{
    private MainMap()
    {
        WithTable("tblThings");
        Where("Type = 0");
    }
}

public class OthersMap : ClassMap<OtherStuff>
{
    private OthersMap ()
    {
        WithTable("tblThings");
        Where("Type = 1");
    }
}

I remember using the Where() some time ago in a different project, but it's not recognized now. Is there any alternative approach?

UPDATE: Turns out that we're using an outdated fluent nhib library what doesn't have the Where() yet., so I need to find an alternative for it.

You could combine Fluent NHibernate with the mapping by xml approach. Use the XML one to map those classes where you need these conditions and fluent for the others. Look here how to combine the approaches: using fluent-nhibernate and traditionally hbm.xml together

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM