Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally I am a big fan of code generation. I roll my own homebrew XML, and at build time I run it through an XSLT to generate my .CS files. I describe the process in this post <a href="http://rusanu.com/2009/04/11/using-xslt-to-generate-performance-counters-code/" rel="noreferrer">Using XSLT to generate Performance Counters code</a>. Although the link discusses generating performance counters code, I use the same process to generate my DAL.</p> <p>So I would create an XML like:</p> <pre><code>&lt;query name="LoadCustomerByName" returns="Customer"&gt; &lt;parameter name="name" type="String"/&gt; &lt;text&gt;SELECT ... FROM Customers WHERE name=@name&lt;/text&gt; &lt;/query&gt; </code></pre> <p>and then the XLST would transform this into something like:</p> <pre><code>public Customer LoadCustomerByName( SqlConnection conn, SqlTransaction trn, String name) { using (Sqlcommand cmd = new SqlCommand(@"SELECT ... FROM ...", conn, trn)) { cmd.Parameters.AddWithValue("@name", name); using (SqlDataReader rdr = cmd.ExecuteReader ()) { Customer c = new Customer(); // Load c from rdr return c; } } } </code></pre> <p>Now I let out a lot of details of what the XSLT transformation actually does, but the really important thing is that this method gives me absolute control over how I create my DAL and it is flexible in every aspect, since the generated .CS code is entirely driven by my XSLTs. I can change the XLST and this will result in re-generation of every single method in my DAL. It makes for easy exploration of various solutions, it allows me to add instrumentation to the code (like counters to measure each individual query performance and use frequency) and many more.</p> <p>This is what basically the various VS designers do for you, but if you take the extra step to control the code generation process, you have a lot more flexibility and control over the result.</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. 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.
    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