Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have hand-written SQL, you can use ExecuteQuery, specifying the type of "row" class as a function template argument:</p> <pre><code>var myList = DataContext.ExecuteQuery&lt;MyRow&gt;( "select * from myview"); </code></pre> <p>The "row" class exposes the columns as public properties. For example:</p> <pre><code>public class MyRow { public int Id { get; set; } public string Name { get; set; } .... } </code></pre> <p>You can decorate the columns with more information:</p> <pre><code>public class MyRow { .... [Column(Storage="NameColumn", DbType="VarChar(50)")] public string Name { get; set; } .... } </code></pre> <p>In my experience linq to sql doesn't generate very good SQL code, and the code it does generate breaks down for large databases. What linq to sql does very well is expose stored procedures to your client. For example:</p> <pre><code>var result = DataContext.MyProcedure(a,b,c); </code></pre> <p>This allows you to store SQL in the database, while having the benefits of an easy to use, automatically generated .NET wrapper.</p> <p>To see the exact SQL that's being used, you can use the SQL Server Profiler tool:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms187929.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms187929.aspx</a></p> <p>The Linq-to-Sql Debug Visualizer:</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx</a></p> <p>Or you can write custom code to log the queries:</p> <p><a href="http://goneale.wordpress.com/2008/12/31/log-linq-2-sql-query-execution-to-consoledebug-window/" rel="nofollow noreferrer">http://goneale.wordpress.com/2008/12/31/log-linq-2-sql-query-execution-to-consoledebug-window/</a></p>
 

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