Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 14th, 2013  |  syntax: None  |  size: 1.76 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class IncidentRepository
  2. {
  3.     public static IList<AuditReport> GetAllIncidentsToAudit()
  4.     {
  5.         DetachedCriteria dc = DetachedCriteria.For<Incident>("i")
  6.             .SetProjection(
  7.                 Projections.ProjectionList()
  8.                     .Add(Projections.Property("i.Id"), "IncidentId")
  9.                     .Add(Projections.Property("l.Id"), "LocationId")
  10.             )
  11.             .CreateCriteria("Locations", "l")
  12.                 .Add(Expression.Eq("l.PrimaryLocationFlag", "T"))
  13.             .SetResultTransformer(Transformers.AliasToBean<AuditReport>());
  14.  
  15.         return ActiveRecordMediator<AuditReport>.FindAll(dc);
  16.     }
  17. }
  18.  
  19. public class AuditReport
  20. {
  21.     public int IncidentId { get; set; }
  22.     public int LocationId { get; set; }
  23. }
  24.        
  25. You have accessed an ActiveRecord class that wasn't properly initialized. There are two possible explanations: that the call to ActiveRecordStarter.Initialize() didn't include castle.AuditReport class, or that castle.AuditReport class is not decorated with the [ActiveRecord] attribute.
  26.        
  27. ISession sess = ActiveRecordMediator.GetSessionFactoryHolder().
  28.         CreateSession(typeof(ActiveRecordBase));
  29.     ICriteria criteria = sess.CreateCriteria<Incident>("i")
  30.         .SetProjection(
  31.             Projections.ProjectionList()
  32.                 .Add(Projections.Property("i.Id"), "IncidentId")
  33.                 .Add(Projections.Property("l.Id"), "LocationId")
  34.         )
  35.         .CreateCriteria("Locations", "l")
  36.             .Add(Expression.Eq("l.PrimaryLocationFlag", "T"))
  37.         .SetResultTransformer(Transformers.AliasToBean<AuditReport>());
  38.  
  39.     return criteria.List<AuditReport>();
  40.        
  41. [Import( typeof( AuditReport ), "AuditReport" )]
  42.        
  43. select new OrderSummary(o.Foo, count(o.Foo))
  44.     from Orders o
  45.     group by o.Bar