NHibernate usando QueryOver con DONDE ADENTRO


Crearía un QueryOver como este

SELECT *
FROM Table
WHERE Field IN (1,2,3,4,5)

He intentado con el método Contains pero me he encontrado con la Excepción

" Sistema.Excepción: Método no reconocido llamada: Sistema.String: El booleano Contiene (System.String) "

Aquí mi código

var qOver = _HibSession.QueryOver<MyModel>(() => baseModel)                                                                
  .JoinAlias(() => baseModel.Submodels, () => subModels)
  .Where(() => subModels.ID.Contains(IDsSubModels))
  .List<MyModel>();
Author: Guillermo Gutiérrez, 2011-03-23

3 answers

He encontrado la solución!! :-)

var qOver = _HibSession.QueryOver<MyModel>(() => baseModel)
    .JoinAlias(() => baseModel.Submodels, () => subModels)
    .WhereRestrictionOn(() => subModels.ID).IsIn(IDsSubModels)
    .List<MyModel>();
 58
Author: Faber,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-13 22:42:50

Puedes probar algo como esto:

// if IDsSubModels - array of IDs
var qOver = _HibSession.QueryOver<MyModel>() 
                       .Where(x => x.ID.IsIn(IDsSubModels))

No necesitas un join en esta situación

 46
Author: Artem G,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-31 10:02:34

Esto funciona y es más elegante

var Strings = new List<string> { "string1", "string2" };

var value = _currentSession
.QueryOver<T>()
.Where(x => x.TProperty == value)
.And(Restrictions.On<T>(y=>y.TProperty).IsIn(Strings))
.OrderBy(x => x.TProperty).Desc.SingleOrDefault();

where T is a Class and TProperty is a property of T
 11
Author: Arnold,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-12 00:05:12