DataTable to IQueryable<T>

  • When we need store data which are in DataTable rather as objects in IQuerable<T>, we can use code as below.
            DataTable dataTable = GetDataTable();
 
                var importdata = from row in dataTable.AsEnumerable()
                            select new ImportRow()
                            {
                                GroupExtID = row.Field<int>(SubjectsImportStructure.PID),
                                ExtID = row.Field<int>(SubjectsImportStructure.ID),
                                Condition = row.Field<int>(SubjectsImportStructure.Condition),
                                IC = row.Field<string>(SubjectsImportStructure.IC),
                                RC = row.Field<string>(SubjectsImportStructure.RC),
                            };
 
            IQueryable<IImportRow> data = importdata as IQueryable<IImportRow>;
programming/csharp/linq/datatabletoiqueryable.txt · Last modified: 2018-06-21 19:48 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0