.net - Return typed DataTable from Linq Query -


After

I have a (hacked) XML, which I wrote in a query in LINQ by a dataset:

  code => productlist = dsProducts.Products.AsEnumerable () where (from prds.field & lt PRDS; string & gt ;. ("productid") (searchpattern) || prds.field & lt; string & gt; ; ("ProductName"); (searchpattern);  

This list is fine, but if I try to say:

  return (DataSetProducts.productsDataTable) productlist.Skip (start). Take (pagesize ) .CopyToDataTable ();  

It says that it can not change the system. DataTable to DataSetProducts.productsDataTable, although this is a similar table.

How to back up typewormed datatars

Good, CopyToDataTable Knowing whether the right strong DataTable DataRow has no type of type for type, DataRow does not Do not provide that information (which is embarrassed IMHO).

Perhaps you can write your own copydata data, which will take another type of parameter to specify the table type. Something like this:

  Public stable teething copyToddable & lt; TROW, TTable & gt; (This IEnumerable & lt; Row & gt; line) where TRow: DataRow, new () where TTable: DataTable, new () {TTable table = new TTable (); Advance (line rows in rows) {copy row = new row (); Object [] itemArcopy = new object [row.ItemArray.Length]; Line.itemarere.copyto (mediate, 0); RowCopy.ItemArray = ItemArray; Table.Rows.Add (rowCopy); } Return table; }  

Edit:

How can I use this new function in the example above?

You should keep this extension method in a stable class. If you add a class to a different namespace, make sure to import that namespace into a scope with a using the section.

Then you can use that method (you should specify the TTable type type parameter can not be estimated by the compiler):

  Returns Product List . Skip (Start). Move (pages). Coptodydable & lt; Dataset Products.ProductsRo, DatasetProducts.productsDateTable & gt; ();  

Please note that I have not tested this code, some bugs may be ...


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -