title: Using LINQ expression to assign to an object's property
body: <p>So I'm working with an old data model, and I kind of have to work within what I've been handed.</p>
  
  <p>When I perform a database query, the model returns data as a</p>
  
  <pre><code>List&lt;Dictionary&lt;string, object&gt;&gt;
  </code></pre>
  
  <p>Where for each dictionary, the key is the column name and the value is the column value. As you can imagine, working with this is a nightmare of foreach loops and type casting</p>
  
  <p>I'm hoping to define some POCO viewmodels and then making something that uses LINQ/reflection, and an "assignment binding map" to go from hideous return value to my nice clean POCO. So I could define "maps" with the column names and lambdas to the properties on my POCO, similar to this...</p>
  
  <pre><code>var Map; // type???
  Map.Add("Id", p =&gt; p.Id);
  Map.Add("Code", p =&gt; p.Code);
  Map.Add("Description", p =&gt; p.Description);
  Map.Add("Active", p =&gt; p.Active);
  </code></pre>
  
  <p>Then convert like this...</p>
  
  <pre><code>List&lt;Dictionary&lt;string, object&gt;&gt; Results = MyModel.Query(...);
  List&lt;ProductViewModel&gt; POCOs = new List&lt;ProductViewModel&gt;();
  
  foreach (var Result in Results) // Foreach row
  {
    ProductViewModel POCO = new ProductViewModel();
  
    foreach (var i in Result) // Foreach column in this row
    {
      // This is where I need help.
      // i.Key is the string name of my column.
      // I can get the lambda for this property from my map using this column name.
      // For example, need to assign to POCO.Id using the lambda expression p =&gt; p.Id
      // Or, assign to POCO.Code using the lambda expression p =&gt; p.Code
    }
  
    POCOs.Add(POCO);
  }
  
  return POCOs;
  </code></pre>
  
  <p>Can this be done using some sort of reflection, and if so, how?</p>