linq to nhibernate compareto not supported

前端 未结 3 1702
囚心锁ツ
囚心锁ツ 2020-12-20 08:12

I\'ve got linq to nhibernate query:

var listka = 
    from i in FakturyZakupu.Queryable 
    where String.Compare(i.REJESTRY.REJ_KOD,sbWartoscBetween1.ToStri         


        
相关标签:
3条回答
  • 2020-12-20 08:16

    NHibernate's Linq provider is very extendable. You could extend it to allow any expression, as long as you can write that expression in HQL, since NHibernate's Linq is converting to HQL.

    So, if you write the extension for Between, your code could look like this:

    var listka = 
        from i in FakturyZakupu.Queryable 
        where i.REJESTRY.REJ_KOD.Between(sbWartoscBetween1, sbWartoscBetween2) 
        select i;
    
    lista = listka.ToList();
    

    Here are some links to get you started:

    • NHibernate Linq provider extension by Fabio Maulo
    • Linq to NHibernate: String.Equals with StringComparison option
    • NHibernate 3 - Extending the Linq Provider to fix some System.NotSupportedException
    • NHibernate - Customize the Linq provider to call your user defined SQL functions
    • Linq to NHibernate extensions
    • Creating In and NotIn extension methods for NHibernate 3 Linq Provider
    • Extend NHibernate-LINQ for Regex-Matching
    • Custom LINQ Extensions for NHibernate
    0 讨论(0)
  • 2020-12-20 08:40

    In NHibernate v3.3.3, String.Compare is supported. A String.Compare(MyProp, "value") > 0 in a Where expression would produce sql similar to where MyProp > 'value'.

    0 讨论(0)
  • 2020-12-20 08:40

    With queries like that, you can avoid the compare to by simply using the greater than (>) or less than (<) operators instead of String.Compare. For example:

    var listka =
        from i in FakturyZakupu.Queryable
        where i.REJESTRY.REJ_KOD > sbWartoscBetween1.ToString() &&
        i.REJESTRY.REJ_KOD < sbWartoscBetween2.ToString()
        select i;
    

    Your success with may depend upon your database's interpretation of string comparisons, but should generally work just fine.

    0 讨论(0)
提交回复
热议问题