Hi,
I’ve been trying to get a concurrency example working. Below I fetch the BankAccounts entity, pause the code with a breakpoint, update the record independently with a different sql login. I then run on the code it goes into the CreatePredicate routine (twice for some reason) and seems to create it. The code runs on and saves the updated entity successfully even though I expect it to fail. There are no triggers on the BankAccounts table.
My Configuration
• Post the LLBLGen Pro version + buildnr. 2.6 Final Oct 6 2008
• When it's a problem occuring at runtime, post the Runtime library version. N/A
• When an exception is thrown, post the stacktrace. N/A
• Post the template group + .NET version you're using. VB.Net, Adapter, VS2008, .net framework 3.5
• Post the database type and version you're using. SQL Express 2005
• Post real code See Below
• Explain inheritance hierachies. N/A
• If you're using custom made templates, please explain these as well. N/A
I must be missing something obvious here.
Thanks in advance.
Hugh
Here is the code
Private Sub SimpleButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
Dim obank As New BankAccountsEntity
Dim bRet As Boolean
obank.BankAccId = 140
Using odap As New DataAccessAdapter(FASDatabase.ClientDBConnectionString)
'Fetch the bank and I check the timestamp – consistent with db as expected odap.FetchEntity(obank)
'I put a Breakpoint here on obank.AccName = "test 4"
'Under a different sql login I update the Bank Account record for 140 – timestamp in db gets updated.
obank.AccName = "test 4"
'I am expecting the Update to fail because during the SaveEntity it calls the CreatePredicate
bRet = odap.SaveEntity(obank, True)
'SaveEntity returns true and db updated with AccName = "test 3" and timestamp gets updated
End Using
End Sub
Option Strict Off
Imports SD.LLBLGen.Pro.ORMSupportClasses
Imports FAS.HelperClasses
Public Class Concurrency
' VB.NET
<DependencyInjectionInfo(GetType(IEntity2), "ConcurrencyPredicateFactoryToUse"), Serializable()> _
Public Class GeneralConcurrencyPredicateFactory
Implements IConcurrencyPredicateFactory
Public Function CreatePredicate(ByVal predicateTypeToCreate As ConcurrencyPredicateType, _
ByVal containingEntity As Object) As IPredicateExpression Implements _
IConcurrencyPredicateFactory.CreatePredicate
Dim toReturn As IPredicateExpression = New PredicateExpression()
Dim bankacc As FAS.EntityClasses.BankAccountsEntity = CType(containingEntity, FAS.EntityClasses.BankAccountsEntity)
Select Case predicateTypeToCreate
Case ConcurrencyPredicateType.Delete
Case ConcurrencyPredicateType.Save
' only for updates
toReturn.Add(BankAccountsFields.TimeStamp = _
bankacc.Fields("TimeStamp").DbValue)
End Select
End Function
End Class
End Class