views:

412

answers:

1

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.

+2  A: 

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 (int)SexId; }
    set { SexId = (int)value; }
  }
  int SexId {get; set;}
}
Adam
And don't forget to always mark YES for sex.
Rick Ratayczak
lol @ Rick. "Sex - Yes please!" Austin Powers rules.
eduncan911