我有我的这个功能,它从数据库中选择所有房间类型,我正在将数据表中的值转换为通用列表以优化我正在创建的系统的速度我的问题是如何隐藏存储的每个值字段 isActive 具有来自“Active”/“Inactive”数据库的值,我必须在 C#.net 4.0 中将其转换为布尔值,你们可以帮我解决这个问题吗?
internal static List<RoomType> FetchRoomTypeList()
{
List<RoomType> roomTypes = new List<RoomType>();
SqlCommand commRoomTypeSelector = ConnectionManager.MainConnection.CreateCommand();
commRoomTypeSelector.CommandType = CommandType.StoredProcedure;
commRoomTypeSelector.CommandText = "Rooms.asp_RMS_RoomTypeList_Select";
SqlDataAdapter da = new SqlDataAdapter(commRoomTypeSelector);
DataSet ds = new DataSet();
da.Fill(ds);
roomTypes = (from rt in ds.Tables[0].AsEnumerable()
select new RoomType
{
RoomTypeID = rt.Field<int>("RoomTypeID"),
RoomTypeName = rt.Field<string>("RoomType"),
LastEditDate = rt.Field<DateTime>("LastEditDate"),
LastEditUser = rt.Field<string>("LastEditUser"),
IsActive = rt.Field<string>("IsActive") == "Active"
}
).ToList();
return roomTypes;
}
下面的行不返回真值,它总是返回假值
IsActive = rt.Field<string>("IsActive") == "Active"
要求的样本数据: