I am trying to get LINQ to SQL to save changes to an attached object in which the support table has a DateTime column, which I suppose should function to control row versions as described.
The table looks like this:
CREATE TABLE [dbo].[client](
[client_id] [int] IDENTITY(1,1) NOT NULL,
[client_address1] varchar(100) NULL,
[modified_date] datetime NOT NULL,
CONSTRAINT [PK_CLIENT] PRIMARY KEY CLUSTERED ([client_id] ASC) )
The corresponding attributes in the modified_date property are set as follows in the DBML design:
Auto Generated Value: True
Auto-Sync: Always
Nullable: False
Primary Key: False
Read Only: False
Server Data Type: DateTime
Source: modified_date
Time Stamp: True
Update Check: Never
And the received attributes of the modified_date property declaration look correct, as far as I can tell:
[Column(Storage="_modified_date", AutoSync=AutoSync.Always,
DbType="DateTime", IsDbGenerated=true, IsVersion=true,
UpdateCheck=UpdateCheck.Never)]
The process of trying to save changes for the client looks something like this:
var c = new client { client_id = idOfClientToSave };
c.client_address1 = uxAddress1.Text;
using (var ClientData = new ClientDataAccess())
{
ClientData.SaveClient(c);
}
, , , , :
public int SaveClient(client c)
{
c.modified_date = DateTime.Now.ToUniversalTime();
if (c.client_id == 0)
{
_db.GetTable<client>().InsertOnSubmit(c);
}
else
{
_db.GetTable<client>().Attach(c, true);
}
try
{
_db.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch (ChangeConflictException)
{
foreach (var con in _db.ChangeConflicts)
{
con.Resolve(RefreshMode.OverwriteCurrentValues);
}
throw;
}
}
_db.SubmitChanges(ConflictMode.ContinueOnConflict) - ChangeConflict ( _db.SubmitChanges()). , DataContext, DataContext .
.