本文介绍了方法:使用LINQ填充集合属性对象以返回DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Olápessoalboa tarde? Gostaria deumoscosíliodopassar valores para minha propriedade private IEnumerable< OrderDetail>订单详情;。 Gostariadepreenchê-la,masjáprocureialguns exemplos enãacheialgo comestaituação。 Peçoaajuda dos colegas se puder mostrar alguma forma de realizar este procedimentos sem que exact ficar preenchendo dois DataTable para fazer inner join com o Linq。 Vou apresentar a estrutura das课程abaixo e forma que estou realizando busca no Banco de Dados。 [Google traslator:] 大家下午好,你好!我想为我的房产添加价值 私人IEnumerable< OrderDetail>订单详情;。 我想填写它,但我尝试了几个例子,但我发现了一些东西。我请求同事的帮助可以显示一些方法来完成这个程序,而不需要继续填充两个DataTable与Linq的内部联接。 我将呈现的结构以下课程,所以我在数据库中进行搜索。 [/ Google翻译]Olá pessoal boa tarde? Gostaria de um auxílio em passar valores para minha propriedadeprivate 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 propertyprivate 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]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 LINQmasnãodeucerto esta estrutura abaixo da erro: [Google翻译] 我尝试使用LINQ但不确定鉴于以下结构错误: [/ Google翻译]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() }; $ b $bAlguémtemalgum exemplo,dica ou alguma estrutura para realizar este procedimento de preencher a propriedadetipocoleçãodaminha classe? $ b $bAgradeço... [Google翻译] 有没有人有任何示例,提示或某些结构来执行此过程来填充我班级的属性类型集合? 感谢... [/ Google翻译]推荐答案 .ToDataTable 是一个扩展方法由 System.Linq 提供的od,请求您使用与下面相同的内容.ToDataTable is an extension method provided by System.Linq, request you to use the same as given belowqueryNamesScores = 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() } 这篇关于方法:使用LINQ填充集合属性对象以返回DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!