nhibernate - Using DetachedCriteria to return generic list of non-AR type -
I am unhappy with my repository class and tried to execute a query with a different criteria. However, it does not seem that I have to set the result to transform the transformer into a non-AR type.
Public Class Incident Repository {Public Fixed IList & lt; AuditReport & gt; GetAllIncidentsToAudit () {DetachedCriteria DC = DetachedCriteria.For & LT; Incident & gt; ("I") .SetProjection (Projections.ProjectionList () .Add (Projections.Property ("i.Id"), "IncidentId") .Add (Projections.Property ("l.Id"), "LocationId")) .CreateCriteria ("Location", "L") .Add (Expression.Eq ("l.PrimaryLocationFlag", "T")) .SetResultTransformer (Transformers.AliasToBean & lt; AuditReport & gt; ()); Return ActiveRecordMediator & lt; AuditReport & gt; .FindAll (DC); }} Public Sector AuditReport {Public Inc. IncidentId {get; Set; } Get public int location ID {}; Set; }}
When I execute this query I get:
You have access to an ActiveRecord class that was not properly started there There can be two reasons: that call to ActiveRecordStarter.Initialize () did not include the castle.AuditReport class, or that is not decorated with the castle.AuditReport class [ActiveRecord] attribute.
I understand the error but how can I return a strongly written list of non-AR types? I have seen NHibernate. Transform offers but nothing stands.
Besides, is it doing bad behavior?
EDIT: I have been implementing my benchmark in the underlying database session and from there.
ISISIS asus = Active Record MDiator GetSationFinderHolder () CreateSession (typeof (ActiveRecordBase)); ICriteria criteria = sess.CreateCriteria & LT; Incident & gt; ("I") .SetProjection (Projections.ProjectionList () .Add (Projections.Property ("i.Id"), "IncidentId") .Add (Projections.Property ("L. Id"), "LocationId")) .CreateCriteria ("Location", "L") .Add (Expression.Eq ("l.PrimaryLocationFlag", "T")) .SetResultTransformer (Transformers.AliasToBean & lt; AuditReport & gt; ()); Return criteria List & lt; AuditReport & gt; ();
Now I'm thinking, is there any other way to achieve it without manually creating a new session?
If you want to use a class for conversion-results, Import ".
Try decorating an AR class (or perhaps AuditReport, but it may be required to be an AR decorated square):
[import (typeof (AuditReport) ), "AuditReport")]
This translates into the XML-config for the NHibernate import attribute.
This resolves at least when a square is created in HQL, such as:
select new order summary. F.O., count (o.Foo)) from Orders O group by BR
Comments
Post a Comment