views:

161

answers:

0

I have the following entities (simplified for this example) mapped using Fluent NHibernate:

public class Stock : Security
{
 public virtual string TickerName { get; set; }
 public override string GetName()
 {
  return TickerName;
 }
}

public class Fund : Security
{
 public virtual string FullName { get; set; }
 public virtual string TickerDomain { get; set; }
 public override string GetName()
 {
  return FullName;
 }
}

public abstract class Security
{
 public virtual int Id { get; set; }
 public virtual string Ticker { get; set; }
 public virtual string ISINCode { get; set; }
 public abstract string GetName();
}

public class Holding
{
 public virtual int Id { get; set; }
 public virtual Security Security { get; set; }
 public virtual int Units { get; set; }
 public virtual decimal AcquisitionValue { get; set; }
}

There's also a Client entity that has one ore more Policy. Each Policy has holdings (Holding) of securities (Stock and Fund). I would like to use a report (HoldingReport) for displaying securities that are currently in any policy's holdings. The HoldingReport is just a DTO and it's unmapped. The report should count how many policies that currently has a holding of the security and include the name (from the GetName method) and type of security (Stock or Fund). Here's the HoldingReport.

public class HoldingReport
{
 public virtual string SecurityType { get; set; }
 public virtual string SecurityName { get; set; }
 public virtual int ActiveHoldings { get; set; }
}

How would you do this using Criteria and DetachedCriteria?