我正在使用通用列表来存储通过查询数据库来的数据。我使用实际用于多行的类列表。 但我的问题是我的课有近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