nHibernate 生成了这个 SQL 的奇数位; SQLS 是否按原样使用它?

nHibernate generated this odd bit of SQL; did SQLS consume it as is?

作为以下 LINQ 的结果:

plans
  .Where(p => p.Attributes.Any(a => a.Attribute.Product.Type == callType) && 
    call.StartTime < p.EndDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MaxValue.Value) &&
    call.StartTime > p.StartDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value))

计划类似于移动 phone 计划。假设国际电话的基本价格为每分钟 1 美元,并且该合同的开始和结束时间为空,因为它是基本价格。制定了 12 月的特别计划,从 1 号开始到该月的最后一天结束。这个计划应该覆盖基础(稍后,它会以 .OrderBy endtime-starttime [即计划越短越重要] + .First,但现在我对此并不感兴趣)但它应该只适用于 12 月进行的调用,因此这两个条款确保我们只查找支持调用类型的计划,并且 start/end 日期跨越调用时间

根据 nHibernate 的输出 window 调试,这转换为以下 SQL:

and 
  (exists 
    (
      ..blah blah blah.. 
      where product7_.Type=?
    )
  ) and ?<coalesce(plan4_.EndDate, ?) and ?>coalesce(plan4_.StartDate, ?)

我得到了 EXISTS (blahblahblah),因为它源自 p.Any(),但是尖括号中的时髦 SQL 是什么?

看起来 ) and ?<coalesce(plan4_.EndDate, ?) and ?>coalesce(plan4_.StartDate, ?) 应该是(在常规 SQL 语法中)

and call.starttime BETWEEN COALESCE(plan.StartDate, '1753-01-01') AND COALESCE(plan.EndDate, '9999-12-31')

SQL服务器是否将其作为 nHibernate 的输出进行处理,或者 nHibernate 的其他部分负责将其扩展为更像我的 "regular" SQL 的内容? (nhibernate以sqlserver2008模式运行,但目标为azure)

答案是尖括号中没有时髦的 SQL :)

仔细观察,您查询中的 <(小于)和 >(大于)运算符在 SQL 中也受支持。 缺少空格让您感到困惑。

? 符号是查询中位置参数的常用占位符,因为它们不会与 SQL 文本内联发送(在本例中,call.StartTime 的值和 max/min 日期值)。

你可以理解为:

and :startTime < coalesce(plan4_.EndDate, :sqlTimeMaxValue) and :startTime > coalesce(plan4_.StartDate, :sqlTimeMinValue)

希望对您有所帮助!