title: c# DAL - Interface for business objects
body: <p>I have a Report Interface which has a Run method.</p>
  
  <p>There are different types of reports which implement this interface and each run their own kind of report, getting data from different tables.</p>
  
  <p>Each report, using its own data context, gets data which then populates Business Objects with and at the moment they are returned as an array (I would like to be able to at least return something like a list but because you have to define the list type it makes it a bit more difficult).</p>
  
  <p>Reflection is then used to find out the properties of the returned data.</p>
  
  <p>I hope I have explained this well enough!</p>
  
  <p>Is there a better way of doing this?</p>
  
  <p>By request:</p>
  
  <pre><code>public interface IReport
  {
      int CustomerID { get; set; }
  
      Array Run();
  }
  
  public class BasicReport : IReport
  {
      public int CustomerID { get; set; }
  
      public virtual Array Run()
      {
          Array result = null;
          using (BasicReportsDataContext brdc = new BasicReportsDataContext())
          {
              var queryResult = from j in brdc.Jobs
                                where j.CustomerID == CustomerID
                                select new JobRecord
                                {
                                    JobNumber = j.JobNumber,
                                    CustomerName = c.CustomerName
                                };
  
              result = queryResult.ToArray();
          }
      }
  }
  </code></pre>
  
  <p>The other class then does a foreach over the data, and uses reflection to find out the field names and values and puts that in an xml file.</p>
  
  <p>As it stands everything works - I just can't help thinking there is a better way of doing it - that perhaps my limited understanding of C# doesn't allow me to see yet.</p>