title: Generics and LINQ to XML
body: <p>I am having a go at creating a generic xmlRepository where I can pass in any type and get a list back.</p>
  
  <p>At the moment my code looks like this (Only way I can get it to work):</p>
  
  <pre><code>public IQueryable&lt;TEntity&gt; GetQuery&lt;TEntity&gt;() where TEntity : class
  {
      var filename = GetEntityFileName&lt;TEntity&gt;();
      var doc = XDocument.Load(filename);
      var query = (from p in doc.Descendants(entityName)
                   select (ServiceAccount)p).AsQueryable().Cast&lt;TEntity&gt;();
      return query;
  }
  </code></pre>
  
  <p>I would like to swap out the</p>
  
  <pre><code>select (ServiceAccount)p).AsQueryable().Cast&lt;TEntity&gt;();
  </code></pre>
  
  <p>with</p>
  
  <pre><code>select (TEntity)p).AsQueryable();
  </code></pre>
  
  <p>TEntity is the same object as ServiceAccount,</p>
  
  <p>Is this possible with LINQ to XML?</p>
  
  <p>I have a SQLRepository, using EF, which has the same method in it and I am looking for the LINQ to XML equivalent of </p>
  
  <pre><code>((IObjectContextAdapter)_context).ObjectContext.CreateQuery&lt;TEntity&gt;(entityName);
  </code></pre>
  
  <p>If indeed there is one.</p>