1

Hello Is it possible in nhibernate to createCriteria expression.in with string of csv, for example

public static List<T> ToList(string csvOnly)
    {
        ISession session = NhSessionMenager.Instance.GetSession();
        List<T> l = session.CreateCriteria(typeof(T)).Add(Expression.In("Id",csvOnly)).List<T>().ToList();
        return l;
    }

and the string will be: "1,2,3,4,5,6,7,8" ?

Endiss
  • 699
  • 2
  • 10
  • 23

1 Answers1

2

You can probably use string.split to split these up into an array. I don't think Expression.In takes a comma separated string.

string [] split = csvOnly.Split(new Char [] {','});
List<T> l = session.CreateCriteria(typeof(T)).Add(Expression.In("Id",split)).List<T>().ToList();
Cole W
  • 15,123
  • 6
  • 51
  • 85
  • This option has low performance on memory saving if you give it 1000rows in string;) – Endiss Mar 26 '12 at 13:03
  • 1
    I would be more worried about the sql query at that point then I would be about performance of doing a `string.split` – Cole W Mar 26 '12 at 13:34
  • On some database engines you have a limit of query parameters. In SQL Server it is something around 2000. We already had that problem. – Tobias Oct 25 '16 at 13:09