免责声明:我知道它在SO的很多地方都被问过.
我的查询有点不同.
编码语言:C#3.5
我有一个名为cardsTable的DataTable从DB中提取数据,我有一个类卡,它只有一些属性(没有构造函数)
public class Cards
{
public Int64 CardID { get; set; }
public string CardName { get; set; }
public Int64 ProjectID { get; set; }
public Double CardWidth { get; set; }
public Double CardHeight { get; set; }
public string Orientation { get; set; }
public string BackgroundImage { get; set; }
public string Background { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想将cardsTable数据插入List类型的对象.
我的数据将在其中包含空字段,因此当我转换数据时该方法不应该出错.以下方法是最好的方法吗?
DataTable dt = GetDataFromDB();
List<Cards> target = dt.AsEnumerable().ToList().ConvertAll(x => new Cards { CardID …Run Code Online (Sandbox Code Playgroud)