forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule1.vb
164 lines (134 loc) · 4.24 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
Imports System.Data.Linq
Imports System.Transactions
Imports System.Data.Linq.Mapping
Imports System.Reflection
Imports System.Linq
Module Module1
Sub Main()
' <Snippet2>
' Imports System.Reflection
Dim newCust As New Customer()
newCust.City = "Auburn"
newCust.CustomerID = "AUBUR"
newCust.CompanyName = "AubCo"
db.Customers.InsertOnSubmit(newCust)
Try
db.SubmitChanges(ConflictMode.ContinueOnConflict)
Catch e As ChangeConflictException
Console.WriteLine("Optimistic concurrency error.")
Console.WriteLine(e.Message)
Console.ReadLine()
For Each occ In db.ChangeConflicts
Dim metatable As MetaTable = db.Mapping.GetTable(occ.Object.GetType())
Dim entityInConflict = CType(occ.Object, Customer)
Console.WriteLine("Table name: {0}", metatable.TableName)
Console.Write("Customer ID: ")
Console.WriteLine(entityInConflict.CustomerID)
For Each mcc In occ.MemberConflicts
Dim currVal = mcc.CurrentValue
Dim origVal = mcc.OriginalValue
Dim databaseVal = mcc.DatabaseValue
Dim mi = mcc.Member
Console.WriteLine("Member: {0}", mi.Name)
Console.WriteLine("current value: {0}", currVal)
Console.WriteLine("original value: {0}", origVal)
Console.WriteLine("database value: {0}", databaseVal)
Next
Next
Catch ee As Exception
' Catch other exceptions.
Console.WriteLine(ee.Message)
Finally
Console.WriteLine("TryCatch block has finished.")
End Try
' </Snippet2>
End Sub
' <Snippet1>
Dim db As New Northwnd("c:\northwnd.mdf")
' Make changes here.
Sub MakeChanges()
Try
db.SubmitChanges()
Catch e As ChangeConflictException
Console.WriteLine(e.Message)
' Make some adjustments
'...
' Try again.
db.SubmitChanges()
End Try
End Sub
' </Snippet1>
Sub method2()
' this will be s2
End Sub
Sub method3()
' <Snippet3>
Dim db As New Northwnd("c:\northwnd.mdf")
Using ts = New TransactionScope()
Try
Dim prod1 = db.Products.First(Function(p) p.ProductID = 4)
Dim prod2 = db.Products.First(Function(p) p.ProductID = 5)
prod1.UnitsInStock -= 3
prod2.UnitsInStock -= 5
db.SubmitChanges()
ts.Complete()
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Using
' </Snippet3>
End Sub
' <Snippet6>
Public Sub CreateDatabase()
Dim db As New MyDVDs("c:\...\mydvds.mdf")
db.CreateDatabase()
End Sub
' </Snippet6>
' <Snippet7>
Public Sub CreateDatabase2()
Dim db As MyDVDs = New MyDVDs("c:\...\mydvds.mdf")
If db.DatabaseExists() Then
Console.WriteLine("Deleting old database...")
db.DeleteDatabase()
End If
db.CreateDatabase()
End Sub
' </Snippet7>
End Module
' <Snippet4>
' Code-generating tool defines a partial class, including
' two partial methods.
Partial Class ExampleClass
Partial Private Sub OnFindingMaxOutput()
End Sub
Partial Private Sub OnFindingMinOutput()
End Sub
Sub ExportResults()
OnFindingMaxOutput()
OnFindingMinOutput()
End Sub
End Class
' Developer implements one of the partial methods. Compiler
' discards the other method.
Class ExampleClass
Private Sub OnFindingMaxOutput()
Console.WriteLine("Maximum has been found.")
End Sub
End Class
' </Snippet4>
' <Snippet5>
Public Class MyDVDs
Inherits DataContext
Public DVDs As Table(Of DVD)
Public Sub New(ByVal connection As String)
MyBase.New(connection)
End Sub
End Class
<Table(Name:="DVDTable")> _
Public Class DVD
<Column(IsPrimaryKey:=True)> _
Public Title As String
<Column()> _
Public Rating As String
End Class
' </Snippet5>