Nhibernate + criteria. How to return the result without a single reference object

I have criteria:

ICriteria criteria = Session.CreateCriteria<Entity>()
                .SetFetchMode("Entity1", FetchMode.Eager)
                .SetFetchMode("Entity2", FetchMode.Select)
                .SetMaxResults(max)
                .SetFirstResult(min)
                .Add(Restrictions.Eq("Available", true))
                .CreateAlias("Entity3", "b")//, NHibernate.SqlCommand.JoinType.InnerJoin)
                .Add(Restrictions.Eq("b.Name", variable))
                .SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer());

When I execute this query, all fields from Entity3 are returned. How can I execute it and result in only Entity objects with the specified Entity1 and Entity2 without Entity3?

+3
source share
1 answer

Perhaps this may help.

IList criteria2 = session.CreateCriteria(typeof(class1), "cl1")
.CreateAlias("subclass1.subclass2", "s2")
.CreateAlias("subclass1.subclass3", "s3")
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("s2.NAME"))
.Add(Projections.Property("s3.CODE")))
.List();

You can go as deep as your need into your mapped classes to create an alias.

0
source

Source: https://habr.com/ru/post/1770002/


All Articles