I am trying to delete a selected gridview row using LINQ (No LINQDataSource).
When the selection is changed, the detailsview binding is changed also. I can add a new
I just wanted to add my scenario for anybody who may have this issue.
We use a custom T4 against our Linq to SQL dbml. We basically just modified the original get/set of string properties to automatically trim and set null.
get { return _OfficiantNameMiddle.GetValueOrNull(); }
set
{
value = value.GetValueOrNull();
if (_OfficiantNameMiddle != value)
{
_IsDirty = true;
OnOfficiantNameMiddleChanging(value);
SendPropertyChanging("OfficiantNameMiddle");
_OfficiantNameMiddle = value;
SendPropertyChanged("OfficiantNameMiddle");
OnOfficiantNameMiddleChanged();
}
}
Legacy data in our database had some leading/trailing spaces so any concurrency check on these columns failed to result in a match (it was comparing the trimmed value against the non-trimmed database value). It was really easy to profile SQL, grab the SQL and start commenting out the items in the WHERE clause until it started returning a row during the concurrency check.
Luckily, we have a LastUpdatedOn field in our tables that is automatically set via OnValidate(System.Data.Linq.ChangeAction).
partial void OnValidate(System.Data.Linq.ChangeAction action)
{
if (action == System.Data.Linq.ChangeAction.Insert)
{
CreatedBy = CurrentUserID;
CreatedOn = DateTime.Now;
LastUpdatedBy = CreatedBy;
LastUpdatedOn = CreatedOn;
}
else if (action == System.Data.Linq.ChangeAction.Update)
{
LastUpdatedBy = CurrentUserID;
LastUpdatedOn = DateTime.Now;
}
}
In order to bypass the problem, we just set the concurrency check to Never on all columns except the Primary Key columns and LastUpdatedOn column. This worked for us.