开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜