>public void DeleteClient(int clientId, bool autoCommit = true) > { > var ReordersQuery = from reord in this.Reorders > where reord.ClientId == clientId > select reord; > > if (ReordersQuery.Any()) > //throw "Client " + clientId.ToString() + " can not be deleted because it has related rows in the ReOrders table!"; > > }>
Namespace Framework Public Class Linq Public cMessage As String = "" Public cTableLogError As String = "" Public dDate As Date = Nothing Public lSuccess As Boolean = False Public nMaximumRecord As Integer = 0 Public nQuery As Integer = 0 Public oApp As Framework.App = Nothing Public oProcess As Framework.LXProcess = Nothing Private lLogData As Boolean = False Private oErrorLogField As Collection = New Collection ' This is when we access the class in a desktop mode Public Sub New(ByVal toApplication As Framework.App) oApp = toApplication lLogData = oApp.lLogData End Sub ' This is when we access the class in a Web mode Public Sub New(ByVal toProcess As Framework.LXProcess) oProcess = toProcess oApp = oProcess.oApp lLogData = oProcess.lLogData End Sub Public Function SQLExec() As Boolean Dim llSuccess As Boolean = False Dim loLogData As Framework.LogData = Nothing ' Get the proper definition as per the current scope If oProcess Is Nothing Then loLogData = New Framework.LogData(oApp) Else loLogData = New Framework.LogData(oProcess) End If ' Reset the values cMessage = "" lSuccess = False ' If we are logging If lLogData Then ' Start the log loLogData.cTitle = "LINK query ID=" + nQuery.ToString If Not loLogData.StartLog() Then Return False End If End If Try ' Execute the client code If Not SQLExecClient() Then End If llSuccess = True Catch loError As Exception cMessage = loError.Message ' If we log the error in the Error table If cTableLogError.Length = 0 Then ' Get the proper definition as per the current scope If oProcess Is Nothing Then oApp.ErrorSetup(loError) Else oProcess.ErrorSetup(loError) End If Else ' Log the error in a custom table If Not ErrorLog(loError) Then Return False End If End If End Try ' If we are logging If lLogData Then ' Stop the log If Not loLogData.StopLog() Then Return False End If End If ' Reset the value nQuery = 0 Return llSuccess End Function ' Log an error ' expO1 Error exception object Private Function ErrorLog(ByVal toError As Exception) As Boolean Dim lcField As String = "" Dim loObject As Object = Nothing Dim loInsertRow As Framework.InsertRow = Nothing Dim loValue As Object = Nothing ' Get the proper definition as per the current scope If oProcess Is Nothing Then loInsertRow = New Framework.InsertRow(oApp) Else loInsertRow = New Framework.InsertRow(oProcess) End If ' Insert a record in the table for the log error loInsertRow.cAlias = cTableLogError loInsertRow.ParameterAdd("Message", cMessage) loInsertRow.ParameterAdd("Query", nQuery) loInsertRow.ParameterAdd("StackTrace", toError.StackTrace) ' For each field in the error log field For Each loObject In oErrorLogField ' Initialization lcField = loObject(1) loValue = loObject(2) ' Add the field loInsertRow.ParameterAdd(lcField, loValue) Next If Not loInsertRow.InsertRow() Then Return False End If Return True End Function ' Add the information for a field in the error log ' expC1 Field ' expO1 Value Public Function AddErrorLogField(ByVal tcField As String, ByVal toValue As Object) As Boolean Dim loObject(2) As Object loObject(1) = tcField loObject(2) = toValue oErrorLogField.Add(loObject) Return True End Function Public Overridable Function SQLExecClient() As Boolean Return True End Function End Class End NamespaceThis class contains some framework related functionalities but you'll be able to understand it in seconds.
Public Class LinqProjectSpecificNameHere Inherits Framework.Framework.Linq Public oClient As ClientAPI.ClientService.Contact = Nothing Sub New(ByVal toApplication As Framework.Framework.App) MyBase.New(toApplication) End Sub Public Overrides Function SQLExecClient() As Boolean ' Based on the query Select Case nQuery ' Generate token to retrieve data from this shop Case 5 ' Get all the clients oClient = (From ... End Select Return True End Function End Class...and, from the client application specific logic:
Dim loLinqProjectSpecificNameHere As LinqProjectSpecificNameHere = New LinqProjectSpecificNameHere(oApp) ' Get all the clients loLinqProjectSpecificNameHere.nQuery = 5 If Not loLinqProjectSpecificNameHere.SQLExecClient() Then Return False End IfIf you find something more into the exception, let me know. We are also into that at various projects and, so far, I found best to remain generic.