Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing properties from multiple classes
    primarykey
    data
    text
    <p>I am creating a web application and I have two classes:</p> <pre><code>public class MOrderMain { public int ID { get; set; } public int CompanyID { get; set; } public string CompanyName { get; set; } public DateTime OrderDate { get; set; } public string BillingName { get; set; } public string BillingAddress { get; set; } public string DeliveryName { get; set; } public string DeliveryAddress { get; set; } } public class MOrder { public int ID { get; set; } public int OrhID { get; set; } public int ProID { get; set; } public string Name { get; set; } public int Quantity { get; set; } public double Rate { get; set; } public double Amount { get; set; } public int DeliveredQty { get; set; } } </code></pre> <p>I would like to retrieve details from both classes. For example, I want to get <code>ID</code> and <code>Billing Name</code> from class <code>MorderMain</code> and all the properties from class <code>MOrder</code>. How can I do this?</p> <p>I am getting the values by database. I have the query but how will I assign the data and how will I retrieve from both?</p> <pre><code>var mylist = new List&lt;MOrder&gt;(); _con = _db.GetConnection(); if (_con.State.Equals(ConnectionState.Closed)) { _con.Open(); } _cmd = new SqlCommand("Get_All_Order_Details", _con) { CommandType = CommandType.StoredProcedure }; _dr = _cmd.ExecuteReader(); while (_dr.Read()) { mylist.Add(new MOrder { ID = Convert.ToInt32(_dr["ordID"]), OrhID = Convert.ToInt32(_dr["orhID"]), ProID = Convert.ToInt32(_dr["proID"]), Name = _dr["pName"].ToString(), Quantity = Convert.ToInt32(_dr["ordQty"]), Rate = Convert.ToDouble(_dr["ordRate"]), Amount = Convert.ToDouble(_dr["ordAmount"]), DeliveredQty = Convert.ToInt32(_dr["ordQtyDelivered"]) }); } return mylist; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload