I am using ES 2007.1.1210, with SQL Server provider (connecting to SQLExpress 2005 for dev/testing) and VS 2005/VB.NET
I have added timestamp fields to the tables and regenerated the classes in order to have concurrency exceptions thrown when editing collisions occur.
I use a vb.net unit test based on the ES unit test to check that concurrent editing raises an exception (see below). However, although the record doesn't get overwritten the exception is not raised.
Is something required to switch on concurrency exceptions?
This is the table definition:
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[clients]') AND type in (N'U'))
BEGIN
CREATE TABLE [clients](
[id] [int] IDENTITY(1,1) NOT NULL,
[student_id] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[first_name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[last_name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[phone] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[mobile] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[timestamp] [timestamp] NOT NULL,
[created] [datetime] NOT NULL,
[modified_by] [int] NOT NULL,
CONSTRAINT [PK_clients] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
END
GO
Here is the unit test code I am using (based directly on the ES test):
Code:
Dim test_id As Integer
Try
Dim c As New BusinessObjects.Clients
c.AddNew()
c.FirstName = String.Format("FIRSTNAME {0}", 1)
c.LastName = String.Format("LASTNAME {0}", 1)
c.StudentId = String.Format("11")
c.ModifiedBy = Me._support.StaffUser.Id
c.Save()
test_id = c.Id
c = New BusinessObjects.Clients
c.LoadByPrimaryKey(test_id)
c.FirstName = "MODIFIED BY 1"
Dim c2 As New BusinessObjects.Clients
c2.LoadByPrimaryKey(test_id)
c2.FirstName = "MODIFIED BY 2"
c.Save() ' written to db
c2.Save() ' not written to db, but no exception!
Assert.Fail("Concurrency exception not thrown")
Catch cex As EntitySpaces.Interfaces.esConcurrencyException
Assert.AreEqual("Error", cex.Message.ToString.Substring(0, 5))
Catch ex As Exception
Assert.Fail(ex.ToString)
Finally
Dim c As New BusinessObjects.Clients
c.LoadByPrimaryKey(test_id)
c.MarkAsDeleted()
c.Save()
End Try