Search code examples
linqnhibernatelinq-to-nhibernateicriteria

ICriteria and Linq to NHibernate together


How can I create one query using both ICriteria and Linq? Example:

var q = Session
.Query<T>()
.Where(x.Id == 1)
.ToCriteria()
.Add(Restrictions.Eq("Title", "Ayende @ Rahien"))
.List<T>();

Solution

  • I think, you should use QueryOver for it:

    var q = Session
    .QueryOver<T>()
    .Where(x.Id == 1)
    .Add(Restrictions.Eq(Projections.Property<T>(x.Title), "Ayende @ Rahien"))
    .List<T>();