title: Dynamically build select list from linq to entities query
body: <p>I'm looking for a way to dynamically create a select list from a iQueryable object.</p>
  
  <p>Concrete example, i want to do something like the following:</p>
  
  <pre><code>public void CreateSelectList(IQueryable(of EntityModel.Core.User entities), string[] columns)
  {
      foreach(var columnID in columns)
      {
          switch(columnID)
          {
              case "Type":
                  SelectList.add(e =&gt; e.UserType);
                  break;
              case "Name":
                  SelectList.add(e =&gt; e.Name);
                  break;
              etc....
          }
      }
      var selectResult = (from u in entities select objSelectList);
  }
  </code></pre>
  
  <p>So all properties are known, i however don't know beforehand what properties are to be selected. That will be passed via the columns parameter.</p>
  
  <p>I know i'm going to run into issues with the type of the selectResult type, because when the select list is dynamic, the compiler doesn't know what the properties of the anonymous type needs to be.</p>
  
  <p>If the above is not possible: The scenario I need it for is the following:<br>
  I'm trying to create a class that can be implemented to display a paged/filtered list of data. This data can be anything (depends on the implementations).The linq used is linq to entities. So they are directly linked to sql data. Now i want to only select the columns of the entities that i am actually showing in the list. Therefore i want the select to be dynamic. My entity might have a hundred properties, but if only 3 of them are shown in the list, i don't want to generate a query that selects the data of all 100 columns and then only uses 3 of them. If there is a different approach that I haven't thought of, I'm open to ideas</p>
  
  <p>Edit:</p>
  
  <p>Some clarifications on the contraints:<br>
  - The query needs to work with linq to entities (see question subject)<br>
  - an entity might contain 100 columns, so selecting ALL columns and then only reading the ones i need is not an option.<br>
  - The end user decides what columns to show, so the columns to select are determined at run time<br>
  - i need to create a SINGLE select, having multiple select statements means having multiple queries on the database, which i don't want</p>