I have a field in my database that stores an integer value and contains the sum of the bitwise values selected in a list. For instance:
VALUE DESCRIPTION
----- -----------
1 Option 1
2 Option 2
4 Option 3
8 Option 4
Let's say Options 2 & 4 are selected, so the value stored in the field would be 10.
I'm having a hard time figuring out (if it's even possible) how to represent this in the hbm.xml file.
Here is a generic example of what I'm trying to do:
Product Table Columns
Id, int
Name, varchar(25)
Services, int
Service Table Columns
Id, int
Name, varchar(25)
Product.cs
public class Product
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Service> Services { get; set; }
}
Service.cs
public class Service
{
public virtual int Id { get; set; } // bit values: 1, 2, 4, 8, ...
public virtual string Name { get; set; }
}
Product.hbm.xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AppNS" namespace="AppNS">
<class name="Product" table="Product">
<id name="Id" column="Id" type="int">
<generator class="native"/>
</id>
<property name="Name" column="Name" type="string"/>
<????? name="Services" column="Services" type="AppNS.Service"/>
</class>
</hibernate-mapping>
Service.hbm.xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AppNS" namespace="AppNS">
<class name="Service" table="Service">
<id name="Id" column="Id" type="int">
<generator class="native"/>
</id>
<property name="Name" column="Name" type="string"/>
</class>
</hibernate-mapping>
I need help with the <????> part in the Product.hbm.xml file.
--EDIT--
Ultimately, I want to be able to call the Load() method to get my Product model back.
Configuration cfg = new Configuration();
...
ISessionFactory sf = cfg.BuildSessionFactory();
using (ISession s = sf.OpenSession())
{
Product product = s.Load<Product>(100);
foreach(Service service in product.Services)
{
Console.WriteLine(service.Name);
}
}
Output would be:
Option 2
Option 4