简体   繁体   English

流利的NHibernate类映射和条件

[英]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. 我记得前一段时间在另一个项目中使用Where() ,但现在无法识别。 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. 更新:事实证明,我们使用的是一个过时的,流畅的nhib库,但还没有Where() 。因此,我需要找到一个替代方法。

You could combine Fluent NHibernate with the mapping by xml approach. 您可以将Fluent NHibernate与xml方法的映射结合起来。 Use the XML one to map those classes where you need these conditions and fluent for the others. 使用XML来映射那些您需要这些条件并能使其他条件流利的类。 Look here how to combine the approaches: using fluent-nhibernate and traditionally hbm.xml together 在这里看看如何结合这些方法:一起使用fluent-nhibernate和传统的hbm.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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