Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to intercept the SQL generated by L2S and fiddle with that, your best option is to create a wrapper classes for SqlConnection, SqlCommand, DbProviderFactory etc. Give a wrapped instance of SqlConnection to the L2S datacontext constructor overload that takes a db connection. In the wrapped connection you can replace the DbProviderFactory with your own custom DbProviderFactory-derived class that returns wrapped versions of SqlCommand etc.</p> <p>E.g.:</p> <pre><code>//sample wrapped SqlConnection: public class MySqlConnectionWrapper : SqlConnection { private SqlConnecction _sqlConn = null; public MySqlConnectionWrapper(string connectString) { _sqlConn = new SqlConnection(connectString); } public override void Open() { _sqlConn.Open(); } //TODO: override everything else and pass on to _sqlConn... protected override DbProviderFactory DbProviderFactory { //todo: return wrapped provider factory... } } </code></pre> <p>When using:</p> <pre><code>using (SomeDataContext dc = new SomeDataContext(new MySqlConnectionWrapper("connect strng")) { var q = from x in dc.SomeTable select x; //...etc... } </code></pre> <p>That said, do you <em>really</em> want to go down that road? You'll need to be able to parse the SQL statements and queries generated by L2S in order to modify them properly. If you can instead modify the linq queries to append whatever you want to add to them, that is probably a better alternative.</p> <p>Remember that Linq queries are composable, so you can add 'extras' in a separate method if you have something that you want to add to many queries.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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