forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule1.vb
192 lines (151 loc) · 5.02 KB
/
Module1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
Imports System.Data.Linq
Module Module1
Sub Main()
' <Snippet2>
Dim db As New Northwnd("c:\northwnd.mdf")
db.DeferredLoadingEnabled = False
Dim custQuery = _
From cust In db.Customers _
Where cust.City = "London" _
Select cust
For Each custObj As Customer In custQuery
For Each ordObj As Order In custObj.Orders
ProcessCustomerOrder(ordObj)
Next
Next
' </Snippet2>
End Sub
Sub ProcessCustomerOrder(ByVal ord As Order)
End Sub
Sub SendCustomerNotification(ByVal ord As Customer)
End Sub
Sub ProcessOrder(ByVal ord As Order)
End Sub
Sub method1()
' <Snippet1>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim notificationQuery = _
From ord In db.Orders _
Where ord.ShipVia = 3 _
Select ord
For Each ordObj As Order In notificationQuery
If ordObj.Freight > 200 Then
SendCustomerNotification(ordObj.Customer)
ProcessOrder(ordObj)
End If
Next
' </Snippet1>
End Sub
Sub method3()
' <Snippet3>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim londonOrderQuery = _
From ord In db.Orders _
Where ord.Customer.City = "London" _
Select ord
' </Snippet3>
End Sub
Sub method4()
' <Snippet4>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim londOrderQuery = _
From cust In db.Customers _
Join ord In db.Orders On cust.CustomerID Equals ord.CustomerID _
Select ord
' </Snippet4>
End Sub
Sub method5()
' <Snippet5>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim idQuery = _
From cust In db.Customers, ord In cust.Orders _
Where cust.City = "London" _
Select cust.CustomerID, ord.OrderID
' </Snippet5>
End Sub
Sub method6()
' <Snippet6>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim idQuery = _
From ord In db.Orders _
Where ord.Customer.City = "London" _
Select ord.CustomerID, ord.OrderID
' </Snippet6>
End Sub
Sub method7()
' <Snippet7>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim c As Customer = _
(From cust In db.Customers _
Where cust.CustomerID = 19283).First()
Dim orders = From ord In c.Orders _
Where ord.ShippedDate.Value.Year = 1998
For Each nextOrder In orders
' Do something.
Next
' </Snippet7>
End Sub
Sub method8()
' <Snippet8>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim c As Customer = _
(From cust In db.Customers _
Where cust.CustomerID = 19283).First
c.Orders.Load()
Dim orders = From ord In c.Orders _
Where ord.ShippedDate.Value.Year = 1998
For Each nextOrder In orders
' Do something.
Next
' </Snippet8>
End Sub
Sub method9()
' <Snippet9>
Dim db As New Northwnd("c:\northwnd.mdf")
Dim ds As DataLoadOptions = New DataLoadOptions()
ds.LoadWith(Of Customer)(Function(c) c.Orders)
ds.LoadWith(Of Order)(Function(o) o.OrderDetails)
db.LoadOptions = ds
Dim custQuery = From cust In db.Customers() _
Where cust.City = "London" _
Select cust
For Each custObj In custQuery
Console.WriteLine("Customer ID: " & custObj.CustomerID)
For Each ord In custObj.Orders
Console.WriteLine(vbTab & "Order ID: " & ord.OrderID)
For Each detail In ord.OrderDetails
Console.WriteLine(vbTab & vbTab & _
"Product ID: {0}", detail.ProductID)
Next
Next
Next
' </Snippet9>
End Sub
Sub method10()
' <Snippet10>
Dim db As New Northwnd("c:\northwnd.mdf")
' Preload Orders for Customer.
' One directive per relationship to be preloaded.
Dim ds As DataLoadOptions = New DataLoadOptions()
ds.LoadWith(Of Customer)(Function(cust) cust.Orders)
ds.AssociateWith(Of Customer)( _
Function(cust) _
From ord In cust.Orders _
Where ord.ShippedDate <> DateTime.Today)
db.LoadOptions = ds
Dim custQuery = From cust In db.Customers _
Where cust.City = "London" _
Select cust
For Each custObj In custQuery
Console.WriteLine("Customer ID: " & custObj.CustomerID)
For Each ord In custObj.Orders
Console.WriteLine(vbTab & "Order ID: " & ord.OrderID)
For Each detail In ord.OrderDetails
Console.WriteLine(vbTab & vbTab & _
"Product ID: " & detail.ProductID)
Next
Next
Next
' </Snippet10>
End Sub
End Module