I read the posts about the issue with NEWSEQUENTIALID() and so changed to NEWID(). But, I'm still not getting the result I expect with an app on WM5 using SQLCE with Merge replication.
This code generates generates a ThrowInvalidOperationException() because G.GpsId is null:
Code:
AGps G = new AGps();
G.AddNew();
G.DeviceState = (int)Dev.DeviceState;
G.DriverServiceState = (int)Dev.ServiceState;
G.Save();
_lastSavedPosition_ID = G.GpsId.Value;
But, this works fine:
Code:
AGps G = new AGps();
G.AddNew();
G.GpsId = Guid.NewGuid(); // Pre-assign the GUID
G.DeviceState = (int)Dev.DeviceState;
G.DriverServiceState = (int)Dev.ServiceState;
G.Save();
_lastSavedPosition_ID = G.GpsId.Value;
The table is:
Code:
CREATE TABLE [dbo].[aGps] (
[GpsId] UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID() ROWGUIDCOL,
CONSTRAINT [PK_a_Gps] PRIMARY KEY NONCLUSTERED ([GpsId]) ON [PRIMARY],
[DeviceState] [INT] NULL,
[DriverServiceState] [INT] NULL,
) ON [PRIMARY]
The record is saved either way (with Guids). Any ideas as to what is going on?