Subsonic 3: SimpleRepository. How to map enum to a table column

subsonicsubsonic3

I have a DB table (Profile) to describe a person. This table has a column "Sex" (int).
In .NET part I have:

public enum Sex { Male = 1, Female = 2 } 

public class Profile{
    public int ID {get; set;}
    public Sex Sex {get; set;}
}
...
SimpleRepository _repo = new SimpleRepository("ConnectionString");
_repo.Add<Profile>(profile);

After this operation Subsonic inserts a new row, but a "Sex" field is NULL. I tried INT and VARCHAR type for "Sex" column but without any result. Also I tried another name for enum, for example "SexEnum".
Do you have any ideas? May be some name convention is needed or a special type for a table column.
Thank you in advance.

Best Answer

I assume you're used to using something like .nettiers that will generate enums from lookup tables, however SubSonic does not provide this functionality. If you have a SexId column in your table you could do the following (null checks need adding):

public enum Sex { Male = 1, Female = 2 } 

public class Profile{
  public int ID {get; set;}
  public Sex Sex 
  {
    get { return (Sex)SexId; }
    set { SexId = (int)value; }
  }
  int SexId {get; set;}
}