title: Problem with decimal precision in SQL using Linq to SQL
body: <p>I have a simple query:</p>
  
  <pre><code>var results = from k in db.tree_nodes
                join s in db.stocks
                on k.tree_nodes_id equals s.tree_nodes_id
                into tmpTable
                from rowtmp in tmpTable.DefaultIfEmpty()
                select new
                {
                    stock = (rowtmp.amount == null) ?
                             ((k.code == null) ? (decimal?)null : (decimal?)0)
                             :
                             rowtmp.amount - rowtmp.amount_in_use,
                };
  </code></pre>
  
  <p>This is the generated SQL code:</p>
  
  <pre><code>SELECT 
      (CASE 
          WHEN ([t1].[amount]) IS NULL THEN 
              (CASE 
                  WHEN [t0].[code] IS NULL THEN CONVERT(Decimal(33,4),NULL)
                  ELSE CONVERT(Decimal(33,4),0)
               END)
          ELSE CONVERT(Decimal(33,4),[t1].[amount] - [t1].[amount_in_use])
       END) AS [stock]
  FROM [dbo].[tree_nodes] AS [t0]
  LEFT OUTER JOIN [dbo].[stocks] AS [t1] ON [t0].[tree_nodes_id] = [t1].[tree_nodes_id]
  </code></pre>
  
  <p>The problem is, the generator created <code>Decimal(33,4)</code> when converting the results. So I'm getting "<em>123.4560</em>" in results instead of "<em>123.456</em>" All of my fields in this query are <code>decimal(14,3)</code>. I don't mind the <em>33</em> part but I need to change the <em>,4</em> to <em>,3</em>. How can I do this?</p>