Also habe ich zwei Lösungen gefunden. Ich führe jede Abfrage getrennt durch, als ich die Ergebnisse beschreibe. Es ist wie eine Union, wird aber nicht in der DB ausgeführt, sondern im Gedächtnis.
var b1 = Session.Query<Sale>()
.Where(x => x.FiledA.Contains(filter) || x.FiledB.Contains(filter))
.OrderBy(x => x.Id)
.GroupBy(x => new { x.FiledA, x.FiledB })
.Select(x => new Foo { FullName = x.Key.FiledA, Name = x.Key.FiledB })
.Take(30)
.ToList();
var b2 = Session.Query<Sale>()
.Where(x => x.FiledC.Contains(filter) || x.FiledD.Contains(filter))
.OrderBy(x => x.Id)
.GroupBy(x => new {x.FiledC, x.FiledD})
.Select(x => new Foo {FullName = x.Key.FiledC, Name = x.Key.FiledD})
.Take(30)
.ToList();
var c = Session.Query<Client>()
.Where(x => x.FiledE.Contains(filter) || x.FiledF.Contains(filter))
.OrderBy(x => x.Id)
.GroupBy(x => new { x.FiledE, x.FiledF })
.Select(x => new Foo { FullName = x.Key.FiledE, Name = x.Key.FiledF })
.Take(30)
.ToList();
return b1.Concat(b2)
.Concat(c)
.ToList()
.GroupBy(x => new { x.Name, x.FullName })
.Select(x => x.First())
.Take(30);
ODER
var b1 = Session.CreateCriteria<Sale>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Distinct(Projections.Property("FiledA")), "Name")
.Add(Projections.Property("FiledB"), "FullName"))
.Add(Restrictions.Or(Restrictions.InsensitiveLike("FiledA", filter),
Restrictions.InsensitiveLike("FiledB", filter)))
.AddOrder(Order.Desc("Id"))
.SetMaxResults(30)
.SetResultTransformer(Transformers.AliasToBean<Foo>())
.List<Foo>();
var b2 = Session.CreateCriteria<Sale>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Distinct(Projections.Property("FiledC")), "Name")
.Add(Projections.Property("FiledD"), "FullName"))
.Add(Restrictions.Or(Restrictions.InsensitiveLike("FiledC", filter),
Restrictions.InsensitiveLike("FiledD", filter)))
.AddOrder(Order.Desc("Id"))
.SetMaxResults(30)
.SetResultTransformer(Transformers.AliasToBean<Foo>())
.List<Foo>();
var c = Session.CreateCriteria<Client>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Distinct(Projections.Property("FiledE")), "Name")
.Add(Projections.Property("FieldF"), "FullName"))
.Add(Restrictions.Or(Restrictions.InsensitiveLike("FiledE", filter),
Restrictions.InsensitiveLike("FieldF", filter)))
.AddOrder(Order.Desc("Id"))
.SetMaxResults(30)
.SetResultTransformer(Transformers.AliasToBean<Foo>())
.List<Foo>();
return b1.Concat(b2)
.Concat(c)
.ToList()
.GroupBy(x => new {x.FullName, x.Name})
.Select(x => x.First())
.Take(30);
Sie die answear hier sehen können: http://stackoverflow.com/questions/8591200/union-with-nhibernate-and-criteria – Cesar