title: How do I project to a dictionary with a custom type using Linq to SQL?
body: <p>I am attempting to use Linq to project each row from a DB query into a dictionary that has a custom type as its value. I am unsure of the LINQ syntax to do this? </p>
  
  <p>This is my current attempt (which doesn't compile, but should demonstrate what I am trying to do). I am having trouble with the 'select new...' part.</p>
  
  <pre><code>public class MyClass
  {     
     public Dictionary&lt;int, CustomType&gt; dict;
  }
  
  public class MyType{        
     string Name;
     decimal Value;
  }
  
  var result = (from t in table
                select new {
                   t.Id,
                   new MyType(t.Name,t.Value)
                }).AsEnumerable().ToDictionary();
  </code></pre>
  
  <p>ANSWER:</p>
  
  <p>Thanks Jason. I just used properties and automatic initialisers rather than a constructor. The working code resembles this (any improvements to this are welcome):</p>
  
  <pre><code>public class MyType {        
      public string Name {get;set;}
      public decimal Value { get; set;}
  }
  
  Dictionary&lt;int, CustomType&gt; dict;
  
  dict = (from t in table
          select new {
             id = av.Account.Id,
             mt = new MyType { Name = t.Name, Value = t.Value }
          }).ToDictionary(item =&gt; item.id, item =&gt; item.mt);
  </code></pre>