1. 程式人生 > >DataTable通過Linq轉List

DataTable通過Linq轉List

DataTable dt = dao.GetAnswerInfoByQuestionId(questionId);
            if (dt != null && dt.Rows.Count > 0)
            {
                var rowColl = dt.Rows;
                return (from DataRow row in rowColl
                        select new DBEntityAnswerInfo
                        {
                            ID = CF.ToInt(row["ID"], -1),
                            AnswerCode = CF.ToString(row["AnswerCode"]),
                            AnswerContent = CF.ToString(row["AnswerContent"]),
                            IsResult = CF.ToInt(row["IsResult"], -1)
                        }).ToList();
            }