Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These are basic concepts:</p> <p>There are several LINQ providers shipped with the .Net framework</p> <ul> <li><p>LINQ to Objects. System.Linq. It's the LINQ core and it is designed to work with in-memory collections</p></li> <li><p>LINQ to XML. System.Xml.Linq To work with XML documents</p></li> <li><p>LINQ to DataSet. To work with DataTable, and DataSet objects</p></li> <li><p>LINQ to SQL. System.Data.Linq It is used to work with SQL Server databases</p></li> <li><p>LINQ to Entities. (Entity Framework) Used to work with several databases. It provides a richer API</p></li> </ul> <p>What I think you are trying to do is:</p> <p><em>From a query returned from a LINQ to SQL context, you want to return a collection of <code>DataRow</code> objects.</em></p> <p><strong>There's no simple conversion between a LINQ to SQL object and a DataRow, so if you insist you would need to use reflection to get the desired output</strong>, <a href="https://stackoverflow.com/q/4953209/1268570">Fastest way to fill DataTable from LINQ query using DataContext</a></p> <p>Now if you really want to work with the DataTable objects, then my recommendation is to use a strongly typed DataSet. To create one, simply add a new DataSet object to your project and from the Server Explorer drag tables like you would do with your LINQ to SQL objects</p> <p>If possible, evaluate the decision to use <code>DataRow</code> and instead return the objects generated by LINQ To SQL, or even better create your custom DTO objects</p> <p>About your code, I don't see any reason to try to use a <code>Datatable</code> object (unless you are nto posting that extra code to justify this decision). If you just want to set the <code>DataSource</code> property of a control, simply do the following:</p> <pre><code>var q = from tbl in db.Table1 select tbl; this.myControl.DataSource = q; this.myControl.DataBind(); </code></pre> <p>If you need, you can transform the result into an anonymous object and used it as the <code>DataSource</code>:</p> <pre><code>var q = from tbl in db.Table1 select new { MyNewProperty = tbl.ExistingProperty, AnotherProperty = tbl.MyCoolerProperty }; this.myControl.DataSource = q; this.myControl.DataBind(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload