title: Linq to sql select into a new class
body: <p>My problem is that when I have following 2 queries, 1st one is not populating the CampaignID property but 2nd one does. Here is my code; </p>
  
  <p><strong>query 1</strong>;</p>
  
  <pre><code>var query = from c in _context.MCTargets
                      where c.TargetDateFrom==d1 &amp;&amp; c.TargetDateTo&lt;=d2
                      group c by c.MarketingCampaignID into g
                      select new MSReport{
                          CampaignID = g.Key, // CampaignID is not populated here.
                                 StartDate = d1,
                                 EndDate = d2
                      };
  </code></pre>
  
  <p><strong>query 2</strong>;</p>
  
  <pre><code>var query2 = from c in _context.MCTargets
                      where c.TargetDateFrom == d1 &amp;&amp; c.TargetDateTo &lt;= d2
                      group c by c.MarketingCampaignID into g
                      select new 
                      {
                          CampaignID = g.Key,
                          StartDate = d1,
                          EndDate = d2
                      };
  </code></pre>
  
  <p><strong>MSReport.cs</strong></p>
  
  <pre><code>public class MSReport
  {
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
      public int CampaignID { get; set; }
  
      public MSReport()
      {
          // CampaignID = 0 here  
          // doing something with CampaignID here like setting some calculated properties.    
      }  
   }
  </code></pre>
  
  <p>Thanks in advance and sorry for my poor explanation. </p>