开发者

NHibernate Entity access through projection

开发者 https://www.devze.com 2023-01-20 12:11 出处:网络
I have this mapping file: \'class name=\"WebTools.Data.Common.IHObjekt, WebTools.Data\" table=\"IHObjekt\"\'

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

精彩评论

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