title: How to create Model based C# List from Database
body: <p>I have Models created through Entity Framework as:</p>
  
  <pre><code>public partial class Order
  {
      public Order()
      {
          this.OrderDetails = new HashSet&lt;OrderDetail&gt;();
      }
  
      public int OrderID { get; set; }
      public string OrderNo { get; set; }
      public System.DateTime OrderDate { get; set; }
      public string Description { get; set; }
  
      public virtual ICollection&lt;OrderDetail&gt; OrderDetails { get; set; }
  }
  </code></pre>
  
  <p>Then another Details Table:</p>
  
  <pre><code> public partial class OrderDetail
  {
      public int OrderItemsID { get; set; }
      public int OrderID { get; set; }
      public string ItemName { get; set; }
      public int Quantity { get; set; }
      public decimal Rate { get; set; }
      public decimal TotalAmount { get; set; }
  
      public virtual Order Order { get; set; }
  }
  
   To See the Master Detail Data I made MasterDetails model As:
  
   public class OrderVM
  {
      public string OrderNo { get; set; }
      public DateTime OrderDate { get; set; }
      public string Description { get; set; }
      public List&lt;OrderDetail&gt; OrderDetails {get;set;}
  }
  </code></pre>
  
  <p>I'm trying to make a method that return a LIST with Join query results but 
     I'm receiving #Anonymous type error here is my Code:</p>
  
  <pre><code>public static List&lt;OrderVM &gt; mylist()
      {
          List&lt;OrderVM&gt; slist = new List&lt;OrderVM&gt;();
  
          using (MyDatabaseEntities1 dc = new MyDatabaseEntities1())
          {
              var myvalues = from O in dc.Orders
                            join D in dc.OrderDetails
                            on
                            O.OrderID equals D.OrderID
                            select new
                             {
                                 O.OrderID,
                                 O.OrderDate,
                                 D.Quantity,
                                 D.Rate
                             };
  
  
                foreach(var myorders in myvalues)
                {
                    slist.Add(myorders);
                }
  
                return slist;
  
  
          }
      }
  </code></pre>
  
  <p>I need a help that how I can I create a generic list with database fields</p>