English 中文(简体)
LINQ to “1 of 2 Updateslap” on “SubmitChanges()”
原标题:LINQ to SQL "1 of 2 Updates failed" on "SubmitChanges()"

我正在更新X类及其孩子YY,使用LINQ,然后提出修改意见,并找到这一错误。

X objX = _context.X.ToList().Where(x => x.DeletedOn == null).First();
objX.DeletedOn = DateTime.Now;

EntitySet<Y> objYs = objX.Ys;
Y objY = objYs[0];
objY.DeletedOn = DateTime.Now;

_context.SubmitChanges();

在SubmitChanges() 我有一个例外,即“2份最新消息中有1份没有成功”,没有其他信息说明为什么发生这种情况。 任何想法?

Also the exception type is ChangeConflictException

最佳回答

Sooo what was the cause of the problem - A trigger

我做了一片面画,看到:

When ObjY s DeletedOn property got updated a trigger updated ObjX s property (value in table) called CountOfX

这导致了一个错误,因为LLLQ创建的LQ在其中具有旧的OfX值。

因此,冲突。

如果你发现这一错误的话,那么,库克特人就是开始调查的最佳场所。

ALSO NOT RELATED TO THE QUESTION I am testing LINQ to SQL and ADO.net Framework, weirdly this error happened in LINQ to SQL but not in ADO.net framework. But I like LINQ to SQL for its Lazy Loading. Waiting for EF to get outta beta

问题回答

我不敢肯定错误的原因究竟是什么,但你提供的事例似乎有一些问题。

  • 在(a)方法之前使用ToList()使您的背景从行文中读到整个桌子,将其转换成一个阵列;然后,在同一个行文中,你立即称,哪里将丢掉你装满但不需要的囚室。 为什么不光是:

    页: 1 ......

  • 这种方法将返还多个项目,但例子中的第二行似乎将逐个处理。 似乎正在为收集本身确定删除的财产,但收集后将拥有这种财产。 它应该失败。

  • 你正在使用日期。 如今,该法有两次。 问题不一,除非这将在每次要求时产生如此小的日值。 您请注明日期。 现在,把结果分配给一个变数,以便你利用它的一切都获得相同的价值。

  • 在你有“Y objY = 肥胖症”的地方,如果在任何X的Y收集中没有物品,就会失败。 你们从阵列的受约束的例外中获得了指数。

因此,鉴于这个例子,我不相信任何人会猜测,为什么在这种例子之后仿照的法典会被打破。

In LINQ2SQL 数据背景图表选择实体和储存点。 (非正常数字)

现将更新Check=永无。

我有这样的问题。 当时我正在铺设单一线路。 它拒绝了另一个进程,正在修改这一记录。

我的人工分解过程正在减缓这一职能的正常速度。 当我走过这条路,走过了下游轮机之后的一段。

我的设想不太常见,但这一错误的性质与另一个职能/程序所取代的记录有关。 就我而言,这是另一个进程。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签