【问题标题】:How to add a true/false to a disjunction/conjunction in nhibernate?如何在 nhibernate 中为析取/合取添加真/假?
【发布时间】:2014-09-10 01:16:09
【问题描述】:

看到几篇老帖子提到MyDisjunction.Add(Restrictions.Sql("(1=1)")),但是找不到Sql函数(现在还存在吗?)。

相反,我使用MyDisjunction.Add(Restriction.Where<MyObject>(x => x.SomeProperty == x.SomeProperty))(!= 表示错误),但这感觉就像我在滥用Restriction.Where。有没有更自然的东西可以使用?

【问题讨论】:

    标签: c# nhibernate criteria nhibernate-criteria


    【解决方案1】:

    查看class Expression

    var alwaysTrue = Expression.Sql("1 = 1");
    
    ...
       .Add(alwaysTrue)
    

    但这是来自Expression class 的代码sn-p 来源:

    namespace NHibernate.Criterion
    {
        /// <summary>
        /// This class is semi-deprecated. Use <see cref="Restrictions"/>.
        /// </summary>
        /// <seealso cref="Restrictions"/>
        public sealed class Expression : Restrictions
        ...
    

    【讨论】:

    • 任何未弃用(或半弃用)的选项?
    • 我接受一个被贬低的答案总比没有好,但我仍然对非(半)弃用的解决方案持开放态度。
    猜你喜欢
    • 2018-11-09
    • 2017-11-20
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2023-03-08
    • 2010-11-21
    相关资源
    最近更新 更多