开发者

NHibernate Entity access through projection

I have this mapping file:

'class name="WebTools.Data.Common.IHObjekt, WebTools.Data" table="IHObjekt"'  
  ....
'property name="TYPBEZEICH" type="string"' 
...  
'many-to-one name="standort" column="STANDORT_ID" fetch="join"'  

And I would like to use a 'Projections.ProjectionList()' to reduce the number of returned columns from the query.

I do this:

'ICriteria criteria = Session.CreateCriteria(typeof(Data.Common.IHObjekt));'  
'ProjectionList projectionList = Projections.ProjectionList();'  
..   
'projectionList.Add(Projections.Property("standort.CODE"));'  

And receive this error:

NHibernate.QueryException: could not resolve property: standort.CODE of: WebTools.Data.Common.IHObjekt

I am trying to access a child entity but it appears I can only access the values in my parent class. Like:

'projectionList.Add(Projec开发者_运维百科tions.Property("TYPBEZEICH"));' 

Can anyone provide some code that will let me use projection to access an entity in a child class?


You need to create an alias in order to reference properties of the child entity.

ICriteria criteria = Session.CreateCriteria(typeof(Data.Common.IHObjekt));

criteria.CreateAlias("standort", "s", JoinType.InnerJoin);

ProjectionList projectionList = Projections.ProjectionList();
projectionList.Add(Projections.Property("s.CODE"));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜