forked from dotnetcore/FreeSql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitTest1.vb
193 lines (154 loc) · 7.88 KB
/
UnitTest1.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
193
Imports System
Imports FreeSql.DataAnnotations
Imports Xunit
Namespace FreeSql.Tests.VB
Public Class UnitTest1
<Fact>
Sub IsNothing()
Dim sql = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100 AndAlso a.Title Is Nothing).ToSql()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Id] = 100 AND a.[Title] IS NULL)", sql)
Dim lst = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100 AndAlso a.Title Is Nothing).ToList()
End Sub
<Fact>
Sub TestSub()
REM VB.net ±í´ïʽ½âÎö¼æÈÝÐÔ²âÊÔ
Dim id As Integer = 100
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToSql())
Dim List1 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToSql())
Dim List2 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToSql())
Dim List11 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToSql())
Dim List22 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToList()
Dim idNullable As Integer? = 100
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToSql())
Dim List222 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToSql())
Dim List3 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToList()
Dim title As String = "xxx"
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToSql())
Dim List4 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToSql())
Dim List5 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToSql())
Dim List6 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] = a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToSql())
Dim List7 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[Title] <> a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> a.Title).ToSql())
Dim List71 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2, a.[IsDeleted] as3, a.[IdNullable] as4, a.[Id] as5, a.[Title] as6
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a, a.Id, a.Title}))
Dim List8 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a, a.Id, a.Title})
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a.Id, a.Title}))
Dim List81 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a.Id, a.Title})
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
FROM [Testvb] a
WHERE (a.[IsDeleted] = 1)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToSql())
Dim List9 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToList()
REM Microsoft.VisualBasic.CompilerServices.Operators.CompareObjectEqual(
g.sqlserver.Delete(Of Testvb2).Where("1=1").ExecuteAffrows()
g.sqlserver.Delete(Of Testvb).Where("1=1").ExecuteAffrows()
g.sqlserver.Insert(New Testvb With {.Id = 1, .Title = "title1"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb With {.Id = 2, .Title = "title2"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb With {.Id = 3, .Title = "title3"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 1, .TestvbId = 1, .Context = "Context11"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 2, .TestvbId = 1, .Context = "Context12"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 3, .TestvbId = 1, .Context = "Context13"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 4, .TestvbId = 2, .Context = "Context21"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 5, .TestvbId = 2, .Context = "Context22"}).ExecuteAffrows()
g.sqlserver.Insert(New Testvb2 With {.Id = 6, .TestvbId = 3, .Context = "Context31"}).ExecuteAffrows()
Dim List10 = g.sqlserver.Select(Of Testvb).IncludeMany(Function(a) a.Testvb2s).ToList()
BaseEntity.Initialization(g.sqlserver, Nothing)
Dim cowR As CowRecord = New CowRecord
cowR.Id = 1
cowR.Lact = 1
cowR.VetCount = 1
cowR.Save()
cowR.VetCount += 1
cowR.Update()
End Sub
End Class
End Namespace
Class Testvb
Property Id As Integer
Property Title As String
Property IsDeleted As Boolean
Property IdNullable As Integer?
Property Testvb2s As List(Of Testvb2)
End Class
Class Testvb2
Property Id As Integer
Property TestvbId As Integer
Property Testvb As Testvb
Property Context As String
End Class
<Index("uk_Primary", "Id,Lact", True)>
Public Class CowRecord
Inherits BaseEntity(Of CowRecord)
Private _Id As Integer
Private _Lact As Integer
Private _Pen As Integer
Private _BDAT As Date?
Private _FDAT As Date?
Private _DDAT As Date?
Private _EDAT As Date?
Private _ARDAT As Date?
Private _MKDAT As Date?
Private _BFDAT As Date?
Private _USDAT As Date?
Private _RC As Integer
Private _DMLK1 As Integer
Private _VetCount As Integer
<Column(IsPrimary:=True)>
Public Property Id As Integer
Get
Return _Id
End Get
Set(value As Integer)
_Id = value
End Set
End Property
<Column(IsPrimary:=True)>
Public Property Lact As Integer
Get
Return _Lact
End Get
Set(value As Integer)
_Lact = value
End Set
End Property
Public Property VetCount As Integer
Get
Return _VetCount
End Get
Set(value As Integer)
_VetCount = value
End Set
End Property
End Class