zoukankan      html  css  js  c++  java
  • NHibernate 数字类型进行模糊查询

    I have a NHibernate search function where I receive integers and want to return results where at least the beginning coincides with the integers, e.g.

    received integer: 729
    returns: 729445, 7291 etc.

    The database column is of type int, as is the property "Id" of Foo.

    But

    int id = 729;
    
    var criteria = session.CreateCriteria(typeof(Foo))
    
    criteria.Add(NHibernate.Criterion.Expression.InsensitiveLike("Id", id.ToString() + "%"));
    
    return criteria.List<Foo>();
    
    

    does result in an error (Could not convert parameter string to int32). Is there something wrong in the code, a work around, or other solution?

    int id = 729;
    
    var criteria = session.CreateCriteria(typeof(Foo))
    
    criteria.Add(NHibernate.Criterion.Expression.InsensitiveLike("Id", id.ToString() + "%"));
    
    return criteria.List<Foo>();

    How about this:

    int id = 729;
    
    var criteria = session.CreateCriteria(typeof(Foo))
    criteria.Add(Expression.Like(Projections.Cast(NHibernateUtil.String, Projections.Property("Id")), id.ToString(), MatchMode.Anywhere));
    
    return criteria.List<Foo>();
  • 相关阅读:
    发红包案列——继承和集合
    抽象类
    方法重写
    继承——访问成员变量,访问成员方法,访问构造方法
    js异步计时器
    栈(stack)和堆(heap)
    高并发和多线程概念
    集群、负载均衡、分布式、微服务
    Redis性能监控
    Redis配置
  • 原文地址:https://www.cnblogs.com/ulex/p/12360549.html
Copyright © 2011-2022 走看看