Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Olá pessoal boa tarde? Gostaria de um auxílio em passar valores para minha propriedade

private IEnumerable<OrderDetail> orderDetail;.

Gostaria de preenchê-la, mas já procurei alguns exemplos e não achei algo com esta situação. Peço a ajuda dos colegas se puder mostrar alguma forma de realizar este procedimentos sem que precise ficar preenchendo dois DataTable para fazer inner join com o Linq.

Vou apresentar a estrutura das Classes abaixo e forma que estou realizando a busca no Banco de Dados.

[Google traslator:]

Good afternoon, hello! I would like to add values to my property

private IEnumerable<OrderDetail> orderDetail;.

I would like to fill it, but I tried a few examples, but I found something with this. I ask the help of colleagues can show some way to do this procedures without need to stay filling two DataTable to inner join with Linq.

I will present the structure of the classes below and so I'm doing the search in the database.
[/Google translator]

C#
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);

.....
}


Tentei usar com o LINQ mas não deu certo esta estrutura abaixo da erro:

[Google translator]
I tried to use with LINQ but not certain given this structure below the error:
[/Google translator]

Error   1   Cannot implicitly convert type 'System.Collections.Generic.List<System.Data.DataRow>' to 'System.Collections.Generic.IEnumerable<LINQ_TESTE2.OrderDetail>'. An explicit conversion exists (are you missing a cast?) D:\Samples Projetos\Pizzaria\TesteLinq\LINQ_TESTE2\Form1.cs 47  42  LINQ_TESTE2<br />


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()
    };


Alguém tem algum exemplo, dica ou alguma estrutura para realizar este procedimento de preencher a propriedade tipo coleção da minha classe?



Agradeço...

[Google translator]
Does anyone have any example, tip or some structure to perform this procedure to fill the property type collection in my class?



Thank ...[/Google translator]
Posted
Updated 20-Jun-15 21:25pm
v3

1 solution

.ToDataTable is an extension method provided by System.Linq, request you to use the same as given below

C#
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().ToDataTable()
 }
 
Share this answer
 
v2
Comments
Thyago Analista 22-Jun-15 19:45pm    
Could not find this ToDataTable ()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900