title: Using ExpandoObject with anonymous type
body: <p>I've been using the ExpandoObject() workaround for anonymous types that has been discussed on this site. I am running into a problem though as my view won't compile. I have used the following extension:</p>
  
  <pre><code>    public static ExpandoObject ToExpando(this object anonymousObject)
      {
          IDictionary&lt;string, object&gt; anonymousDictionary = new RouteValueDictionary(anonymousObject);
          IDictionary&lt;string, object&gt; expando = new ExpandoObject();
          foreach (var item in anonymousDictionary)
              expando.Add(item);
          return (ExpandoObject)expando;
      }
  </code></pre>
  
  <p>...which allows me to do the following:</p>
  
  <p>Controller:</p>
  
  <pre><code>        var latestDiscussions = repository.Messages
              .OrderByDescending(m =&gt; m.DateCreated)
              .GroupBy(m =&gt; m.Discussion.DiscussionId)
              .Take(10)
              .Join(repository.Discussions,
                  m =&gt; m.Key,
                  d =&gt; d.DiscussionId,
                  (m, d) =&gt; new
                  {
                      Id = m.Key,
                      Title = d.Title,
                      Guid = d.Guid,
                      UrlTitle = d.UrlTitle,
                      ViewCount = d.ViewCount
                  }).ToExpando();
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@foreach (var discussion in Model.Latest)
  {
      &lt;div&gt;
          @Html.RouteLink(discussion.Title, "DisplayDiscussion", new { guid = discussion.Guid, urlTitle = discussion.UrlTitle, action = "Display", controller = "Discussion" })
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>My model looks like this:</p>
  
  <pre><code>public class IndexModel
  {
      public IQueryable&lt;Discussion&gt; MostPopular { get; set; }
      public ExpandoObject Latest { get; set; }
  }
  </code></pre>
  
  <p>However, I am getting a compilation error saying that discussion.Title:</p>
  
  <p>Compiler Error Message: CS1061: 'System.Collections.Generic.KeyValuePair' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'System.Collections.Generic.KeyValuePair' could be found (are you missing a using directive or an assembly reference?)</p>
  
  <p>What am I missing?</p>
  
  <p>Thanks in advance!</p>
  
  <p>Mark</p>