How to refer to enum values inside nhibernate formula mapping specification?

Posted by mark on Stack Overflow See other posts from Stack Overflow or by mark
Published on 2010-03-12T20:44:46Z Indexed on 2010/03/12 20:47 UTC
Read the original article Hit count: 208

Filed under:
|
|

Dear ladies and sirs.

I have two entities types:

  • RunContainer parent entity type
  • Run child entity type

Run has a property Status, which is of type RunStatus, like so:

public enum RunStatus
{
  Created,
  Starting,
  // ...
}
public class Run
{
  public int ContainerId { get; private set; }
  // ...
  public RunStatus Status { get; private set; }
}

RunContainer has a calculated property ActiveRunCount, like so:

public class RunContainer
{
  public int Id { get; private set; }
  // ...
  public int ActiveRunCount { get; private set; }
}

In the mapping for the RunContainer.ActiveRunCount property, I use the formula specification like so:

<property name="ActiveRunCount" formula="(select count(r.Id) from Run r where r.ContainerId = Id and r.Status = 1)"/>

My problem is that I refer to the RunStatus enum values in the formula by their respective numeric value, rather than the appropriate symbolic name. Can anyone tell me how can I use the symbolic name instead?

Thanks.

© Stack Overflow or respective owner

Related posts about nhibernate-mapping

Related posts about formula