I'm considering porting my existing DAL to NHibernate instead.  But
I've been reading the documentation, and there's one feature of the
way my object model currently works that I haven't figured out an
elegant way to do using NHibernate yet.

Say I'm representing a person.  That person has a Gender property.  In
the database, that gender property is a foreign key to
GenderTbl.GenderId, and GenderTbl.Gender holds the string that
describes the person's gender.  What I'm doing currently is having
something like the following:

public class Person
{
    private string gender;
    private static Dictionary<string, int> genderDict;
    private static IList<string> genderList;
    .
    .
    .
    public string Gender
    {
        get
        {
            return gender;
        }
        set
        {
            if (!genderDict.ContainsKey(value))
                throw new ArgumentException("Invalid gender");
            gender = value;
        }
    }

    public IList<string> GenderList
    {
        get
        {
            return genderList;
        }
    }

}

My DAL initializes Person.genderDict and Person.genderList to reflect
the contents of GenderTbl -- genderDict is used to lookup the primary
key of a gender when the Person is serialized back to the database
(there's a UNIQUE constraint on GenderTbl.Gender, so this reverse
lookup will be valid).  I could just as easily do something like:
private int gender;
private Dictionary<int, string> genderForwardDict;
private Dictionary<string, int> genderReverseDict;
public string Gender
{
get{ return genderDict[gender];};
set{ if (!genderReverseDict.ContainsKey(value)) throw new
ArgumentException(); else gender = genderReverseDict[value];}
}

And I'd be fine with that.  What I haven't figured out is how to get
NHibernate to populate a static list of the legal values for the
gender field (genderDict).  Or is there some other way to do this that
I'm missing?  Specifically, I do this so view-related controls can
bind to the list of legal values so the user can select from a combo
box rather than having to perform a search every time or type in a
string, etc.

Thanks!

~Dathan

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to