Problem with NULL values in LINQ Group Join

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Im building a dataset based application using vb.net. I have a dataset which has many datatables. After all the datatables have been filled when the form load, I have a LINQ statement to retrieve data from those datatables as a Group Join Query and fill
to another datatable inside my dataset.
This is my query:
Dim query = From B In Books _<br/>
Group Join RI in RecIn On RI.BookID Equals B.BookID Into BRI = Group _<br/>
From w In BRI.DefaultIfEmpty _<br/>
Group Join BO In BillOut On BO.BookID Equals B.BookID Into BOI = Group _<br/>
From x In BOI.DefaultIfEmpty _<br/>
Group Join BR_I In InOut On BR_I.BookID Equals B.BookID Into BR_I = Group _<br/>
From y In BR_I.DefaultIfEmpty _<br/>
Group Join BO_I In OutIn On BO_I.BookID Equals B.BookID Into BO_I= GROUP _<br/>
From z In BO_I.DefaultIfEmpty _<br/>
Select BookID = B.BookID, BookTitle = B.BookTitle, QTYOUT = x.QTYOUT, QTY_OUT=z.QTY_OUT, QTYIN = w.QTYIN, QTY_IN=y.QTY_IN , Price=b.SellingPrice, Cost=B.OriginalPrice
My problem is that I cannot handle the null value in my query when any of my joined datatable has no data.
Is there anyone can give me a trick to replace a null value with something else?
Here is my sample query result

<br/>
<table id="x_t2" border="0" width="885" style="height:332px
<tbody>
<tr>
<th title="System.String BookID</th>
<th title="System.String BookTitle</th>
<th title="System.Int32? QTYOUT</th>
<th title="System.Int32? QTY_OUT</th>
<th title="System.Int32? QTYIN</th>
<th title="System.Int32? QTY_IN</th>
<th title="System.Decimal? Price</th>
<th title="System.Decimal? Cost</th>
</tr>
<tr>
<td>
F002
</td>
<td>
New Interchange Intro WB
</td>
<td>
6
</td>
<td>
5
</td>
<td>
31
</td>
<td>null</td>
<td>
7000.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F003
</td>
<td>
Side by Side
</td>
<td>
5
</td>
<td>
4
</td>
<td>
1
</td>
<td>null</td>
<td>
9000.0000
</td>
<td>
7000.0000
</td>
</tr>
<tr>
<td>
F005
</td>
<td>
New Interchange 1 WB
</td>
<td>null</td>
<td>
3
</td>
<td>
1
</td>
<td>null</td>
<td>
6500.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F006
</td>
<td>
Listen To Me!
</td>
<td>null</td>
<td>
1
</td>
<td>
20
</td>
<td>null</td>
<td>
7000.0000
</td>
<td>
5600.0000
</td>
</tr>
<tr>
<td>
F009
</td>
<td>
New Interchange 2 WB
</td>
<td>null</td>
<td>
6
</td>
<td>
1
</td>
<td>null</td>
<td>
6500.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F010
</td>
<td>
In the Real World
</td>
<td>
6
</td>
<td>
11
</td>
<td>
1
</td>
<td>null</td>
<td>
8000.0000
</td>
<td>
6800.0000
</td>
</tr>
<tr>
<td>
F011
</td>
<td>
Thoughts & Notions
</td>
<td>
1
</td>
<td>
6
</td>
<td>
1
</td>
<td>null</td>
<td>
8000.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F013
</td>
<td>
New Interchange 3 WB
</td>
<td>
11
</td>
<td>
16
</td>
<td>
1
</td>
<td>null</td>
<td>
6500.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F015
</td>
<td>
Cause & Effect
</td>
<td>null</td>
<td>null</td>
<td>
1
</td>
<td>null</td>
<td>
8000.0000
</td>
<td>
5800.0000
</td>
</tr>
<tr>
<td>
F017
</td>
<td>
New Interchange 4 WB
</td>
<td>null</td>
<td>null</td>
<td>
1
</td>
<td>null</td>
<td>
6500.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F018
</td>
<td>
Vocabulary 1
</td>
<td>null</td>
<td>null</td>
<td>
1
</td>
<td>null</td>
<td>
60000.5000
</td>
<td>
62000.0000
</td>
</tr>
<tr>
<td>
F023
</td>
<td>
Vocabulary 2
</td>
<td>null</td>
<td>
1
</td>
<td>
1
</td>
<td>null</td>
<td>
6000.0000
</td>
<td>
5000.0000
</td>
</tr>
<tr>
<td>
F025
</td>
<td>
New Interchange Intro SB
</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>
26000.0000
</td>
<td>
24000.0000
</td>
</tr>
<tr>
<td>
H025
</td>
<td>
Survival English 1&2
</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>
12000.0000
</td>
<td>
10592.0000
</td>
</tr>
</tbody>
</table>

View the full article
 
Back
Top