forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule1.vb
97 lines (73 loc) · 2.55 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
' <Snippet1>
Imports System.Data.Linq
Imports System.Data.Linq.Mapping
' </Snippet1>
Module Module1
Sub Main()
' <Snippet2>
' Use a connection string, but connect to
' the temporary copy of the database.
Dim db As New Northwnd _
("C:\linqtest2\northwnd.mdf")
' Keep the console window open after activity stops.
Console.ReadLine()
' </Snippet2>
End Sub
Sub method3()
Dim db As New Northwnd _
("C:\linqtest2\northwnd.mdf")
' <Snippet3>
' Create the new Customer object.
Dim newCust As New Customer()
newCust.CompanyName = "AdventureWorks Cafe"
newCust.CustomerID = "A3VCA"
' Add the customer to the Customers table.
db.Customers.InsertOnSubmit(newCust)
Console.WriteLine("Customers matching CA before insert:")
Dim custQuery = _
From cust In db.Customers _
Where cust.CustomerID.Contains("CA") _
Select cust
For Each cust In custQuery
Console.WriteLine("Customer ID: " & cust.CustomerID)
Next
' </Snippet3>
End Sub
Sub method4()
Dim db As New Northwnd _
("C:\linqtest2\northwnd.mdf")
' <Snippet4>
Dim existingCust = _
(From cust In db.Customers _
Where cust.CustomerID = "ALFKI" _
Select cust).First()
' Change the contact name of the customer.
existingCust.ContactName = "New Contact"
' </Snippet4>
' <Snippet5>
' Access the first element in the Orders collection.
Dim ord0 As Order = existingCust.Orders(0)
' Access the first element in the OrderDetails collection.
Dim detail0 As OrderDetail = ord0.OrderDetails(0)
' Display the order to be deleted.
Console.WriteLine _
(vbCrLf & "The Order Detail to be deleted is: OrderID = " _
& detail0.OrderID)
' Mark the Order Detail row for deletion from the database.
db.OrderDetails.DeleteOnSubmit(detail0)
' </Snippet5>
' <Snippet6>
db.SubmitChanges()
' </Snippet6>
' <Snippet7>
Console.WriteLine(vbCrLf & "Customers matching CA after update:")
Dim finalQuery = _
From cust In db.Customers _
Where cust.CustomerID.Contains("CA") _
Select cust
For Each cust In finalQuery
Console.WriteLine("Customer ID: " & cust.CustomerID)
Next
' </Snippet7>
End Sub
End Module