[Serializable]
public class Sex
{
/// <summary>[变量]编号</summary>
private int? id;
/// <summary>[变量]名字</summary>
private string name;
/// <summary>[属性]编号</summary>
public int? Id
{
get { return id; }
}
/// <summary>[属性]名字</summary>
public string Name
{
get { return name; }
}
/// <summary>实例化对象方法。私有仅供内部访问</summary>
private Sex()
{
}
public static readonly Sex Empty = new Sex();
public static readonly Sex Male = new Sex()
{
id = 1,
name = "男"
};
public static readonly Sex Female = new Sex()
{
id = 2,
name = "女"
};
public static readonly Sex Unknown = new Sex()
{
id = 0,
name = "未知"
};
/// <summary>所有“性别”对象列表。</summary>
public static readonly List<Sex> AllList = new List<Sex>
{
Sex.Male,
Sex.Female,
Sex.Unknown
};
/// <summary>根据“性别”编号,返回一个“性别”对象。</summary>
public static Sex GetDataById(int id)
{
foreach (Sex tmpSex in AllList)
{
if (tmpSex.Id == id)
return tmpSex;
}
return null;
}
/// <summary>已重写的ToString方法,当该类作为其它类的一个属性时,在数据控件中可以直接绑定并显示其有意义的名称。</summary>
public override string ToString()
{
return Name;
}
public class Sex
{
/// <summary>[变量]编号</summary>
private int? id;
/// <summary>[变量]名字</summary>
private string name;
/// <summary>[属性]编号</summary>
public int? Id
{
get { return id; }
}
/// <summary>[属性]名字</summary>
public string Name
{
get { return name; }
}
/// <summary>实例化对象方法。私有仅供内部访问</summary>
private Sex()
{
}
public static readonly Sex Empty = new Sex();
public static readonly Sex Male = new Sex()
{
id = 1,
name = "男"
};
public static readonly Sex Female = new Sex()
{
id = 2,
name = "女"
};
public static readonly Sex Unknown = new Sex()
{
id = 0,
name = "未知"
};
/// <summary>所有“性别”对象列表。</summary>
public static readonly List<Sex> AllList = new List<Sex>
{
Sex.Male,
Sex.Female,
Sex.Unknown
};
/// <summary>根据“性别”编号,返回一个“性别”对象。</summary>
public static Sex GetDataById(int id)
{
foreach (Sex tmpSex in AllList)
{
if (tmpSex.Id == id)
return tmpSex;
}
return null;
}
/// <summary>已重写的ToString方法,当该类作为其它类的一个属性时,在数据控件中可以直接绑定并显示其有意义的名称。</summary>
public override string ToString()
{
return Name;
}
}
后台调用
Sex tmpSex = Sex.GetDataById(0);
if (tmpSex != null) userInfo.Sex= tmpSex;
sql语句
Sex=case Sex when 0 then '未知' when 1 then '男' else '女' end