【问题标题】:For Fluent NHibernate experts: Join with where condition对于流利的 NHibernate 专家:加入 where 条件
【发布时间】:2012-12-06 21:06:17
【问题描述】:

SQL Server 语法是:

select tableAColumn1, tableAColumn2, tableBColumn1
from tableA, tableB
where ISNUMERIC(tableAColumn1) = 1
and CONVERT(INT, tableAColumn1) = tableBColumn1
and tableAColumn2 = 'something'

在 Fluent NHibernate 中实现这一目标的最佳方法是什么?我需要多少个类来帮助获得生成的 ClassMap?它是什么样子的?

编辑:

public class BarausInfoMap : ClassMap<BarausInfo>
    {
        public BarausInfoMap()
        {
            Table("BARAUS");

            Id(x => x.nr);

            Map(x => x.betrag);

            Join("BARAUSLANG", m =>
            {
                m.Fetch.Join();

                m.KeyColumn("Ula");
                m.Map(x => x.bezeichnung);
                m.Map(x => x.sprache);
                m.Map(x => x.la);
                this.Where("m.la = 'SPE'");
            });
        }
    }

nr 列是 int 并且 ula 列是字符串,但我需要加入这 2 个。另外,this.where 是指我猜的外部表,但它应该指的是内部表。

【问题讨论】:

  • 你能展示你到目前为止所做的事情吗?
  • 确定没问题添加到原帖

标签: nhibernate join where fluent


【解决方案1】:

也许使用单独的实体和单独的映射比构建查询更好

queryOver<BarausInfo>.JoinQueryOver(x => x.BarauslangObject, barauslangAlias, JoinType.InnerJoin, conjunction)

并且连词将包含ISNUMERIC(tableAColumn1) = 1 和tableAColumn2 = 'something'。在 BarausInfo 映射中,您可以指定类似 References(v => v.BarauslangObject).Formula("CONVERT(INT, tableAColumn1) = tableBColumn1") 之类的内容。只需了解如何正确指定公式中的列即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多