title: Use generic method to return list<T> where T could be one of three types that share the same structure
body: <p>I have some sql views where different source tables are used, but each view returns exactly the same structure.</p>
  
  <p>So very simplistically:</p>
  
  <pre><code>view1
      select tblA.Name as custName,
             tblA.DOB as DateOfBirth,
             tblA.accountBalance as AccountBalance
      from myFirstTable tblA
  
  view2
      select tblB.AccountName as custName,
             tblB.BirthDate as DateOfBirth,
             tblB.Balance as AccountBalance
      from mySecondTable tblB
  
  view3
      select tblC.CustomerName as custName,
             tblC.DateOfBirth as DateOfBirth,
             tblC.accBal as AccountBalance
      from myThirdTable tblC
  </code></pre>
  
  <p>So even though the fieldnames in the source tables are different, the different views return identically-named (and typed) fields. The actual views are complex and massive, running to hundreds of lines each.</p>
  
  <p>I then drag these views into my Linq-to-sql designer and try and use them in a generic class.</p>
  
  <pre><code>    public static List&lt;T&gt; MainSearch&lt;T&gt;(ReportParams RP)
      {
          MyDataContext dc = new MyDataContext();
  
          if (string.IsNullOrEmpty(RP.appType)) { return null; }
  
          var searchQuery = new List&lt;T&gt;();
  
          switch (RP.appType)
          {
              case "type1":
                  searchQuery = (from t in dc.view1s select t);
                  break;
              case "type2":
                  searchQuery = (from t in dc.view2s select t);
                  break;
              case "type3":
                  searchQuery = (from t in dc.view3s select t);
                  break;
          }
  
          //do other stuff with search query depending on params
          DateTime dtFrom = Convert.ToDateTime(RP.fromDate);
          searchQuery = searchQuery.Where(q =&gt; convert.ToDateTime(q.DateOfBirth) &gt;= dtFrom);
  
          //and so on...
  </code></pre>
  
  <p>The idea being that a generic front end can be used that passes in parameters depending on user selection and then these parameters are used to narrow down the search results for the specific source data being searched for (it will never be a combination returned, it's always one or other of the three views).</p>
  
  <p>The code above does not work. In my switch statement, the intellisense complains that it cannot implicitly convert from a specific type (of view1, for example) to a generic list of T.  This then stops me using the strong types in lambda expressions further down.</p>
  
  <p>Is there any way to achieve what I'm trying to do or am I barking up completely the wrong tree here?</p>