I'm using Enums to map simple bits of data for my various business objects. In most cases this work fine since I have a single value stored in the BO. One of my business objects needs to have multiple "types".
There are two relevant database tables, Projects, and ProjModes. There is actually a third that is essentially a look-ip for ProjModes, but I'm trying to replace the look-up table with an enumeration (which I've done successfully with single values).
It is the collection/list aspect that seems to be giving me problems.
Code:
public enum ProjectMode
{
Web = 0,
Mail,
DataEntry,
Phone,
Consulting,
DataAnalysis,
FocusGroup,
CognitiveIntrviews,
Other = 100,
}
My current implementation of Project is as follows (irrelevant bits removed):
Code:
public class Project : DomainObject<int>
{
private IList<ProjectMode> m_Modes;
public virtual IList<ProjectMode> Modes
{
get { return m_Modes; }
set { m_Modes = value;}
}
}
The edited schema:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="dbo">
<class name="SESRC.Scheduler.Core.Domain.Project, SESRC.Scheduler.Core" table="ut_Projects">
<id name="ID" type="Int32" column="prKey">
<generator class="identity" />
</id>
<bag name="Modes" access="property" lazy="false" cascade="none" table="ut_ProjModes">
<key column="prKey"/>
<element column="prMode" type="SESRC.Scheduler.Core.Domain.ProjectMode, SESRC.Scheduler.Core" />
</bag>
</class>
</hibernate-mapping>
ProjectDao - My data access object where I'm trying to do a query on a sub-set of the Modes list. Relevant method listed:
Code:
public IList<Project> GetAllProjects(ProjectType type)
{
//ArrayList projects = new ArrayList();
IList<ProjectMode> projects = new List<ProjectMode>();
projects.Add(ProjectMode.Mail);
projects.Add(ProjectMode.Phone);
IQuery query =
NHibernateSession.CreateQuery(
"FROM Project as pj WHERE pj.Modes IN (:ProjectModes)");
// Filter on type if set.
switch (type)
{
case ProjectType.Funded:
query.SetParameterList("ProjectModes", projects);
break;
case ProjectType.All:
break;
}
// Get the data
IList<Project> projectList = query.List<Project>();
return (IList<Project>)projectList;
}
The problem seems to be with the IQuery handling the collection. I get this error: "unindexed collection before []". I'm not certain if it has a problem with the Modes collection or the projects collection I'm sending the IQuery.
Is there a better approach for handling a list of enumerations? Should I make it a full blown Business Object? Make some sort of ValueObject?
Any help appreciated,
Jack