3
我有一个像UserEntity一类,如下转换列表<DataRow>在C#.NET中列出<UserEntity>
[Serializable]
[XmlRootAttribute(ElementName = "UsersEntity", IsNullable = false)]
public class UserEntity
{
[XmlElement(DataType="string",ElementName="UsersID")]
public int UsersID { get; set; }
[XmlElement(DataType = "string", ElementName = "UserName")]
public string UserName { get; set; }
[XmlElement(DataType = "string", ElementName = "Password")]
public string Password { get; set; }
}
然后我填充的纪录从数据库table.and数据集则没有foreach循环我转换该数据集到列表如下
Dataset _ods= new Dataset();
//create a list of UerEntity class
List<UserEntity> lstUsers=new List<UserEntity>();
// populate record as dataset from DB table
_ods = populateEmpData();
// convert List<DataRow> from Dataset withou Foreach Loop
List<DataRow> lstRows = _ods.Tables[0].AsEnumerable().ToList();
现在我想通过使用ConvertAll方法转换lstRows为文章
lstUsers=lstRows.ToList().ConvertAll(new Converter(ent=>ent));
但它不起作用。我怎样才能做到这一点?
你会如何转换一个DataRow到UserType?你会写'DataRow x = ent'吗? –