System.Data.Linq.ChangeConflictException:未找到行或更改未找到、Data、System、ChangeConflictException

2023-09-02 20:45:41 作者:没有很喜欢你

我想删除使用LINQ选定的GridView的行(无 使用LinqDataSource)。

I am trying to delete a selected gridview row using LINQ (No LINQDataSource).

当选择改变时,在DetailsView结合被改变 也。我可以添加一个新的条目到数据库中,但是当我说这 code到里面的UpdatePanel一个删除按钮,我得到了一个例外:

When the selection is changed, the detailsview binding is changed also. I can add a new entry to the database, but when I added this code to a delete button inside the updatePanel, I got an exception:

try
{           
    var query = from i in db.QuestionModules 
                where i.QuestionModuleID == QuestionModuleID 
                select i;

    QuestionModule o = query.First();
    db.QuestionModules.DeleteOnSubmit(o);
    db.SubmitChanges();
}

这是个例外,我得到:

System.Data.Linq.ChangeConflictException: Row not found or changed. at
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode
failureMode) at
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges() 

我有这个问题,一个星期左右,而且无论我做什么,这是 仍然存在,并记录不被删除。

I've had this problem for about a week, and no matter what I do, it is still there, and the record doesn't get deleted.

在做什么任何想法?

推荐答案

确定 - 它看起来好像(在我的情况下,至少),得到的答复是,设置的所有的非主键列的UpdateCheck的财产到的从不的在DBML文件。这样做可以立即治愈未找到或更改行的问题。

OK - it looks as though (in my case at least) the answer was to set all non primary-key column's UpdateCheck property to Never in the DBML file. Doing this immediately cured the problem of "Row not found or changed".

由于微软正在蛾成球的LINQ到SQL支持实体框架,人们不禁要问是否这些类型的错误将是固定的谣言?

Given the rumour that Microsoft are moth-balling Linq-To-Sql in favor of Entity Framework, one wonders whether these sorts of bugs will be fixed?