' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
﻿Imports System
Imports System.Linq

Namespace Global.Tx.NonXADB.EF
	Public Class Bad
		Inherits DBI
		Public Overrides Function GetDbContext() As MyDbContext
			Return New MyDbContext("MYSQL")
		End Function
		Public Overrides Sub Test()
			For i As Integer = 0 To 9
				Using ctx As MyDbContext = GetDbContext()
					Try
						Dim osrc As TblSrc = ctx.TblSrc.First(Function(row) row.Id = 1)
						osrc.Val = osrc.Val - 1
						ctx.SaveChanges()
						If i Mod 2 <> 0 Then
							Throw New Problem()
						End If
						Dim otrg As TblTrg = ctx.TblTrg.First(Function(row) row.Id = 1)
						otrg.Val = otrg.Val + 1
						ctx.SaveChanges()
					Catch ex As Problem
						Console.WriteLine("Problem")
					End Try
				End Using
			Next
		End Sub
		Public Shared Sub Main(args As String())
			Demo(New Bad())
			Console.ReadKey()
		End Sub
	End Class
End Namespace
