I would like an aid in passing values to my property with private IEnumerable<OrderDetail> orderDetail;
.
I would like to fill it out, but I have already looked for some examples and did not find anything with this situation. I ask your colleagues for help if you can show some way to do this without having to fill in two DataTable to do inner join with Linq .
I will present the structure of the Classes below and form that I am conducting the search in the Database.
public class Order
{
public string orderNumber { get; set; }
public DateTime orderDate { get; set; }
private DateTime requiredDate { get; set; }
private DateTime shippedDate { get; set; }
public int customerNumber { get; set; }
public bool status { get; set; }
public string comments { get; set; }
private IEnumerable<OrderDetail> orderDetail;
public virtual IEnumerable<OrderDetail> OrderDetails
{
get { return orderDetail; }
set { orderDetail = value; }
}
public Order()
{
orderDetail = new List<OrderDetail>();
}
//No formulário do Evento Load
private void Form1_Load(object sender, EventArgs e)
{
myConnection = new MySqlConnection(myConnString);
myConnection.Open();
MySqlDataAdapter conexaoAdapter =
new MySqlDataAdapter("select O.*, D.* " +
"from Orders O " +
"INNER JOIN OrderDetails D " +
"ON O.orderNumber = D.orderNumber ", myConnection);
conexaoAdapter.Fill(DataTableDatbase);
.....
}
I tried using LINQ but this structure did not work under the error:
Error 1 Can not implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?) D: \ Samples Projects \ Pizzeria \ TestLinq \ LINQ_TESTE2 \ Form1.cs 47 42 LINQ_TESTE2
IEnumerable<Order> queryNamesScores =
from Listorder in DataTableDatbase.Tables["Orders"].AsEnumerable()
select new Order()
{
orderNumber = DataTableDatbase.Tables[0].Rows[0]["orderNumber"].ToString(),
OrderDetails = (from scoreAsText in DataTableDatbase.Tables["OrderDetails"].AsEnumerable()
select scoreAsText).ToList()
};
Does anyone have an example, hint, or any structure to accomplish this procedure to populate the collection type property of my class?