tags:

views:

72

answers:

1

I have this table:

create table dbo.NotificationsIn
(
    NotificationID varchar(18) primary key,
    ArrivalTime datetime not null default getdate()
)

I insert to it like this:

public void InsertNotification(NotificationsIn notification)
{
    db.NotificationsIns.InsertOnSubmit(notification);
    db.SubmitChanges();
}

where db is a LINQ DataContext.

I get the following exception after I insert a new record:

System.InvalidOperationException: Member AutoSync failure. For members to be Auto-Synced after insert, the type must either have an auto-generated identity, or a key that is not modified by the database after insert.

In the dbml, I have set the ArrivalTime property AutoGenerated = True and Auto-Sync = OnInsert. I have also tried Auto-Sync = Never, but the result is the same.

Any idea why I am getting this exception? Thank you.

A: 

You have not provided your database layer information.
The simplest solution is to make the NotificationID column an Identity one. This should help.

Devart
The database is sql server 2k8. I can't make the NotificationID an Identity because it's value matters; it is supplied by an external system.
Eric
Then the better solution is to call the Refresh method. The AutoSync property is intended to be used with autogenerated properties, Refresh does not have this limitation. http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx
Devart
But the Auto-Sync property of NotificationID is already set to Never. ArrivalTime is set to Auto-Sync OnInsert, but it is autogenerated.
Eric