我正在使用通用列表來存儲通過查詢數據庫來的數據。我使用實際用於多行的類列表。 但我的問題是我的課有近20多個屬性,大部分時間我只使用其2或3個屬性。 所以我想知道什麼是保持數據來自數據庫的最佳方式。在通用列表中存儲來自數據庫的數據
下面是我的代碼
List<ImageGalleryCollection> tempList = new List<ImageGalleryCollection1>();
SqlConnection connection = Dal.GetConnection();
SqlParameter[] paramList = new SqlParameter[1];
paramList[0] = new SqlParameter("@cityId", cityId);
SqlDataReader data = Dal.ExecuteReaderSP(SPNames.GetRegCity, paramList, connection);
while(data.Read())
{
ImageGalleryCollection igc = new ImageGalleryCollection1();
igc.cityPhotoGalleryId = Convert.ToInt32(data["cityPhotoGalleryId"]);
igc.ImagePath = data["imagePath"].ToString();
tempList.Add(igc);
}
data.Close();
connection.Close();
return tempList;
在ImageGalleryCollection我有更多的20個物業及以上的,我只使用了兩個properties.I認爲這是非常低效的
在這種情況下,我必須創建多個類 – Vishwajeet
使用OOP原則。 – Kalanamith