tags:

views:

99

answers:

3

when using createCriteria, how to specify SELECT..WHERE.. IN (value1, val2...) ?

+3  A: 

You could use Restrictions.in method.

Darin Dimitrov
+6  A: 

See Restrictions.in:

List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.in( "name", new String[] { "Fritz", "Izi", "Pk" } ) )
skaffman
A: 

What if the Restrictions.in should be used on a list eg:

public class MainEntity
{
   public virtual int ID { get;set;}
   public virtual string Name { get;set;}
   public virtual IList<SubEntity> SubEntitys { get;set;}

  public MainEntity() { SubEntitys = new List<SubEntity>(); }
}

public class SubEntity
{
   public virtual int ID { get;set;}
   public virtual string Name { get;set;}
}

How can you make
List mainEntitys= sess.createCriteria(mainEntitys.class)    
.add( Restrictions.in( "SubEntity", List<SubEntity>)
Is that an answer or a question? Are why have you posted it in C#?
skaffman
I hope its a question, and sorry i posted it in C# but the main question was about ICriteria and not about language