title: How to convert string with property name to Entity framework storage expression?
body: <p>I need to select specific columns from DB using string with property name in Entity Framework. I use reflections to be able pass complex properties: </p>
  
  <pre><code>public static Object GetPropValue(this Object obj, String name)
  {
      foreach (String part in name.Split('.'))
      {
          if (obj == null) { return null; }
  
          Type type = obj.GetType();
          PropertyInfo info = type.GetProperty(part);
          if (info == null) { return null; }
  
          obj = info.GetValue(obj, null);
      }
      return obj;
  }
  </code></pre>
  
  <p>Then I tried to pass this into Select like this:</p>
  
  <pre><code>string propertyName = "ModemStatus.Temperature"  // This is sent in http request
  DBContext.MyStatuses.Select(x =&gt; x.GetPropValue(propertyName))
  </code></pre>
  
  <p>But I get runtime exception that GetPropValue can not be converted to storage expression, which I understand but I have no idea how to solve it. Any idea?</p>
  
  <p>EDIT: Return type will always be a collection of doubles</p>
  
  <pre><code> ICollection&lt;double&gt; values = DBContext.MyStatuses.Select(x =&gt; x.GetPropValue(propertyName)) 
  </code></pre>