开发者

nhibernate +criteria. How to return result without one referenced entity

开发者 https://www.devze.com 2023-01-20 03:30 出处:网络
I have criteria: ICriteria criteria = Session.CreateCrite开发者_JS百科ria<Entity>() .SetFetchMode(\"Entity1\", FetchMode.Eager)

I have criteria:

ICriteria criteria = Session.CreateCrite开发者_JS百科ria<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 to. How can I execute it and have in result only Entity objects with referenced Entity1 and Entity2 without Entity3?


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 make an alias.

0

精彩评论

暂无评论...
验证码 换一张
取 消