All I am trying to do is find all employees that have a certain roll,
using what I think would be a common setup. Is that an incorrect
assumption? Is there a better way to do this? So many questions, but
if I can only get one answered, it would be - Can this simple HQL
query...
Session.CreateQuery("from Employee e where :role in
elements(e.Roles)").SetEnum("role", RoleType.ActiveMember);
...be done using ICriteria or Queryover?
On Oct 21, 6:02 pm, jcomet <[email protected]> wrote:
> I have what is a common scenario (at least for me) that involves
> filtering based on a collection of enums. I need to do this
> dynamically, so I want to use ICriteria or QueryOver, but I just can't
> figure out how to do it.
>
> I have trimmed down my actual artifacts to outline the issue as simply
> as I can. See the following tables CREATEs, ENUM, POCO, HBM and DAO
> function that works, but uses HQL. Of course, if that is all I needed
> I would be fine with HQL, but I need ICriteria.
>
> CREATE TABLE [dbo].[Employee](
> [ID] [int] IDENTITY(1,1) NOT NULL,
> [LastName] [varchar](50) NOT NULL
> )
>
> CREATE TABLE [dbo].[EmployeeRole](
> [ID] [int] IDENTITY(1,1) NOT NULL,
> [EmployeeID] [int] NOT NULL,
> [RoleID] [int] NOT NULL
> )
>
> public enum RoleType
> {
> ActiveEmployee = 1,
> Admin = 2,
> Other = 3
>
> }
>
> public class Employee
> {
> public virtual int ID { get; set; }
> public virtual string Name { get; set; }
> public virtual IList<RoleType> Roles { get; set; }
>
> }
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> assembly="MyDomain" namespace="MyDomain">
> <class name="MyDomain.Employee,MyDomain" table="Employee"
> lazy="true">
> <id name="ID" column="ID" type="Int32" unsaved-value="0">
> <generator class="native" />
> </id>
> <property name="Name" column="Name" type="string" length="150"
> not-null="true" />
> <bag name="Roles" table="EmployeeRole" inverse="false">
> <key column="EmployeeID" />
> <element column="RoleID" type="MyDomain.RoleType, MyDomain" />
> </bag>
> </class>
> </hibernate-mapping>
>
> public IList<Employee> GetActiveEmployees()
> {
> var employees = base.GetSession()
> .CreateQuery("from Employee e where :role in
> elements(e.Roles)")
> .SetEnum("role", RoleIDEnum.ActiveMember);
>
> return employees.List<Employee>();
>
> }
>
> How can I recode the GetActiveEmployees method to use ICiteria instead
> of HQL?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.