Note that there are some explanatory texts on larger screens.

plurals
  1. POHow merge two sequences into one?
    text
    copied!<p>I have some working code that retrieves data from data base. It is interesting for me to get some better code for my solution. Are there some ways to combine two queries into one or something like this?</p> <pre><code>Dim customerTitlesAndIDs = contex.CustomerTable.Select(Function(row) New With {.ID = row.ID, .CustomerTitle = row.Title}).ToList() Dim cutomerIdPayment = contex.CustomerPayments.Select(Function(table) New With { .ID = table.CustomerID, .Range = table.PaymentsRange, .Values = table.Values }).ToList() Dim customerInfos As New List(Of SCustomerInfo) For Each customer In customerTitlesAndIDs Dim cID As Integer = customer.ID customerInfo.Add(New SCustomerInfo(CreateCustomerTable(), cID, customer.CustomerTitle)) For Each cutomerPayments In cutomerIdPayment If cutomerPayments.ID = cID Then Dim rangeValue(1) As Object rangeValue(0) = cutomerPayments.Range rangeValue(1) = cutomerPayments.Values Dim dtRow As DataRow = customerInfos.Last().PaymentTable.NewRow() dtRow.ItemArray = rangeValue customerInfos.Last().PaymentTable.Rows.Add(dtRow) End If Next Next Return customerInfos </code></pre> <p><strong>Same code with C# (hope no syntax errors occurred):</strong></p> <pre><code>var customerTitlesAndIDs = contex.CustomerTable.Select(row =&gt; new { .ID = row.ID, .CustomerTitle = row.Title }).ToList(); var cutomerIdPayment = contex.CustomerPayments.Select(table =&gt; new { .ID = table.CustomerID, .Range = table.PaymentsRange, .Values = table.Values }).ToList(); List&lt;SCustomerInfo&gt; customerInfos = new List&lt;SCustomerInfo&gt;; foreach (var customer in customerTitlesAndIDs) { int cID = customer.ID; customerInfos.Add(new SCustomerInfo(CreateCustomerTable(), cID, customer.CustomerTitle)); foreach (var cutomerPayments in cutomerIdPayment) { if (cutomerPayments.ID = cID) { object[] rangeValue = new object[1] {cutomerPayments.Range, cutomerPayments.Values}; DataRow dtRow = customerInfos.Last().PaymentTable.NewRow(); dtRow.ItemArray = rangeValue; customerInfos.Last().PaymentTable.Rows.Add(dtRow); } } } </code></pre> <p>SCustomerInfo represented by folowing <code>Structure</code> (code is simplified):</p> <pre><code>Public Structure SWindAltitude Public PaymentTableAs DataTable Public Title As String Public ID As Integer End Structure </code></pre> <p>Both C# and VB.NET solutions will be helpful.</p>
 

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