C# 执行LINQ时出现行未找到或更改错误

C# 执行LINQ时出现行未找到或更改错误,c#,linq,C#,Linq,这是我的密码 using (BatchDashboardDataContext db = new BatchDashboardDataContext()) { TBatchDashboard b = new TBatchDashboard(); b.Id = deletedBatchId; db.TBatchDashboards.Attach(b); db.TBatc

这是我的密码

        using (BatchDashboardDataContext db = new BatchDashboardDataContext())
        {
            TBatchDashboard b = new TBatchDashboard();

            b.Id = deletedBatchId;
            db.TBatchDashboards.Attach(b);
            db.TBatchDashboards.DeleteOnSubmit(b);
            db.SubmitChanges();
        }
Id是
TBatchDashboard
表的主键。另外,在
TBatchDashboard
表中,还有一条记录的主键为
deletedBatchId
值。 请检查一下,给我一些建议。
谢谢。

如果您按照以下方式查询对象,请不要附加该对象:
TBatchDashboards b=db.TBatchDashboards.First(i=>i.Id==d
eletedBatchId);`它有用吗?