dateTable 转换为实体类
需要将DataTable 转化成实体类, 数据库是和实体类相对应的
现在是在每个类里面加了类似下面的方法:
private static List<Albums> ConvertToAlbums(DataTable dt)
{
List<Albums> model = new List<Albums>();
if (dt == null || dt.Rows.Count <= 0)
{
return model;
}
IEnumerable<Albums> query = dt.AsEnumerable().Select(h => new Albums()
{
UserID = h.Field<long>("UserID"),
UserName = h.Field<string>("UserName"),
AlbumID = h.Field<int>("AlbumID"),
AlbumName = h.Field<string>("AlbumName"),
Description = h.Field<string>("Description"),
NewPicture = h.Field<string>("NewPicture"),
PrivacyState = h.Field<byte>("PrivacyState"),
TitlePicture = h.Field<string>("TitlePicture"),
PicturesCount = h.Field<int?>("PicturesCount")
});
model = query.ToList();
return model;
}
数据库里几百个表,也就是最少要写几十个实体类,难道每个类里都要这么写吗?有没有好点的办法。
等待大侠指点·~~~~
实体类,MVC?
------解决方案--------------------给个参考http://blog.csdn.net/qq289523052/article/details/7639041