title: Calling Linq To SQL queries residing in classes from code behind.
body: <p>I am using <code>ASP.NET Web Forms/C#</code>.I am having a page <code>Customer.aspx</code>.I have created <code>CustomerBLL</code> class in which I plan to use <code>Linq To SQL</code> queries to perform all <code>database</code> related tasks.</p>
  
  <p>Consider this example.Here is a method called <code>GetDateFormat()</code> in my <code>CustomerBLL</code> class which returns Date format from <code>database</code>.Here is the code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Data;
  
  namespace CwizBankApp
  {
      public class CustomerBLL
      {
          public string GetDateFormat()
          {
              using (var db = new DataClasses1DataContext())
              {
                  var format = db.CODEs.Where(code =&gt; code.NAME.Equals("dateformat")).SingleOrDefault();  
                  return format.DRNAME;   
              }
          }
  
      }
  }
  </code></pre>
  
  <p>From <code>code behind</code> I am calling this function inside of another function like this.</p>
  
  <pre><code>public void RetrieveDateFormat()
          {
              //In this function we retrieve the date format
              //from the database to identify if it is british or american
  
  
             var format = CustomerBLL.GetDateFormat();  
  
              //The global variable gDateFormat stores the format
             if (format != null)
             {
                 Global.DateFormat = format;
             }
  </code></pre>
  
  <p>I am calling the function and storing the result first and then checking if it is null or not.Should I be doing this way or Should I check if it is null or not in the <code>CustomerBLL.cs</code> file itself?</p>
  
  <p>What is better way to do this.Is my way of calling the function <code>GetDateFormat()</code> feasible.</p>
  
  <p>Also is this approach of maintaining <code>Linq</code> queries in such class files and then calling them from <code>code behind</code>  considered to be a good practice?</p>
  
  <p>Can somebody tell me if I am heading in the right direction or not?</p>
  
  <p>Any suggestions are welcome. </p>