Answered by:
Join 2 List in Web API

Question
-
User746671234 posted
Hello I need this output
{ "Income": 0, "coins": [ { "CoinName": "COIN1", "CoinBal": 0.00, "CoinPrice": 8754.36 }, { "CoinName": "COIN2", "CoinBal": 0.00, "CoinPrice": 101200.00 }, { "CoinName": "COIN3", "CoinBal": 0.00, "CoinPrice": 112603.00 }, { "CoinName": "COIN4", "CoinBal": 0.00, "CoinPrice": 226263.00 } ] }
In my code I have two different lists. How could I join them for the above output. My code
Dim ec As List(Of InrBal) = New List(Of InrBal)() If dt.Tables(0).Rows.Count > 0 Then For i = 0 To dt.Tables(0).Rows.Count - 1 ec.Add(New InrBal() With { .Income = Convert.ToInt32(dt.Tables(0).Rows(i)("Income")) }) Next End If Dim eb As List(Of DashCoins) = New List(Of DashCoins)() If dt.Tables(1).Rows.Count > 0 Then For i = 0 To dt.Tables(1).Rows.Count - 1 eb.Add(New DashCoins() With { .CoinName = dt.Tables(1).Rows(i)("CoinName").ToString, .CoinBal = Convert.ToDecimal(dt.Tables(1).Rows(i)("CoinBal")), .CoinPrice = Convert.ToDecimal(dt.Tables(1).Rows(i)("CoinPrice")) }) Next End If
Now I have to join this two list and send output.
Monday, May 25, 2020 5:57 AM
Answers
-
User746671234 posted
Okay done like this:
Public Class DashClass Public Property InrBal As Object Public Property Coins As Object End Class
Dim dash As New DashClass dash.InrBal = ec.SingleOrDefault dash.Coins = eb
and I merged two Lists data and I got the above result
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 25, 2020 12:19 PM
All replies
-
User475983607 posted
The community needs to know how income and coins are related. Otherwise, this question cannot be answered.
Monday, May 25, 2020 10:08 AM -
User746671234 posted
They both have different results. I am sending this from dataset.
Monday, May 25, 2020 11:01 AM -
User475983607 posted
They both have different results. I am sending this from dataset.
The Coin DataTable needs an IncomeId otherwise there is no way to join the two tables as described in the JSON data.
Monday, May 25, 2020 11:31 AM -
User746671234 posted
Okay done like this:
Public Class DashClass Public Property InrBal As Object Public Property Coins As Object End Class
Dim dash As New DashClass dash.InrBal = ec.SingleOrDefault dash.Coins = eb
and I merged two Lists data and I got the above result
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 25, 2020 12:19 PM -
User475983607 posted
The design only works if there is one income record in table 1 and all the records in table 2 relate to the single record in table 1.
Monday, May 25, 2020 12:35 PM