Last active
November 26, 2015 07:06
-
-
Save rupakraj/5a1d4414fab3f0b26bed to your computer and use it in GitHub Desktop.
C# System.Data.DataTable ->List<Object>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using Select(): a power of LINQ for casting datatable into List of Object | |
List<Student> target = dt.AsEnumerable() | |
.Select(row => new Student | |
{ | |
// assuming column 0's type is Nullable<long> | |
StudentID = row.Field<long?>(0).GetValueOrDefault(), | |
StudentName = String.IsNullOrEmpty(row.Field<string>(1)), | |
}).ToList(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment