score:2
well, copytodatatable
has no way of knowing what is the correct strong datatable
type for a given type of datarow
, since the datarow
doesn't provide that information (which is a shame imho).
perhaps you could write your own copytodatatable method, which would take another type parameter to specify the table type. something like that :
public static ttable copytodatatable<trow, ttable>(this ienumerable<trow> rows)
where trow : datarow, new()
where ttable : datatable, new()
{
ttable table = new ttable();
foreach (trow row in rows)
{
trow rowcopy = new trow();
object[] itemarraycopy = new object[row.itemarray.length];
row.itemarray.copyto(itemarraycopy, 0);
rowcopy.itemarray = itemarraycopy;
table.rows.add(rowcopy);
}
return table;
}
edit :
how can i use this new function in the above example?
you must put this extension method in a static class. if you put the class in a different namespace, make sure to import that namespace in the scope with a using
clause.
you can then use the method like that (you must specify the type parameters since the ttable type can't be inferred by the compiler) :
return productlist.skip(begin).take(pagesize).copytodatatable<datasetproducts.productsrow, datasetproducts.productsdatatable>();
please note that i didn't test this code, there might be a few bugs...
Source: stackoverflow.com
Related Query
- Return typed DataTable from Linq Query
- return Datatable from linq query
- LINQ return 0 if query from DataTable is null
- Filling a DataSet or a DataTable from a LINQ query result set
- LINQ query to return distinct field values from list of objects
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Fastest way to fill DataTable from LINQ query using DataContext
- Return one result from LINQ Query
- Return Type for Collection from LINQ Query
- How to return IGrouping from Linq query when grouping
- Return Anonymous type from LINQ query in VB.NET
- Using Linq to return the count of items from a query along with its resultset
- LinQ query select DataRow from DataTable
- creating Linq to sqlite dbml from DbLinq source code
- .NET service OData return anonymous type from LINQ query
- Fill Datatable from linq query
- how to return anonymous field from Linq query
- Linq query where first column from DataTable is compared to second column for duplicates
- How to return list of items from linq to sql query and call it in a console application
- return a class directly from a linq query
- Query Linq return List<int> from object
- Linq query doesn't return a result from object within another object
- LINQ query to return from one table based on matching another table
- How to return list from linq query using viewmodels
- How do I return a element using LINQ query from an ObservableCollection?
- Create a entity framework LINQ group join query to return a subset of properties from DTO and a list of another DTO, ASP.net core
- How to return values from a LINQ query and display them in a table using C#, ASP.NET MVC and Entity Framework
- linq query to return a string from a list
- How to return query results from method that uses LINQ to SQL
- Error when Copying Query from linq to Datatable
More Query from same tag
- Linq Help. int.Contains and int == iqueryable doesn't work
- SingleOrDefault : Not return null on Custome structure
- Can anything make life easier for a dotnet 3.5 coder trapped in a 1.1 world?
- Slowness when chaining LINQ queries
- Narrowing LINQ query to one column
- LINQ ArgumentException due to AnonymousObject
- How to learn transaction in EF or LINQ to SQL?
- SqlFunctions.StringConvert and Dynamic linq
- Linq - How to aggregate the results of another query
- Get all possible distinct triples using LINQ
- Getting next and previous on a Queryable
- Why query return System.Data.Entity.Infrastructure.DbQuery<T> not T-SQL query string
- how do i union int? and int variables in linqpad
- filter child entities while fetching a parent entity EF Core
- linq projection
- sorting by using linq comparing two lists?
- Filtering Puppeter Sharp's ElementHandle[] with async linq
- method x has no supported translation to SQL when use a static class
- Entity Framework 5 Lambda Queries
- Generic Linq ordering function?
- Find an item from collection based on the minimum value of a property
- Changing collection inside foreach
- How to get List of Properities from System.Collections.IEnumerable using LINQ C#
- Linq query returns values instead of setting values (With example) in C#
- C# LINQ zip function equivalent in query expression
- How to rewrite LINQ Any() to make it suitable for .NET 3.5
- Get an IDataReader from a typed List
- Clean up code using c# linq
- Best way to update in Linq To SQL
- Adding where clause to nested Linq selects