Breeze乐观并发异常保存日期时间

时间:2021-08-19 06:53:58

Here a tricky issue I have with breeze, entity framework and a datetime field.

这里有一个棘手的问题,我有微风,实体框架和日期时间字段。

I get an optimistic concurrency exception when saving the entity due to the date field having the current microseconds added to it on entering and on leaving the breeze system.

由于日期字段在进入和离开微风系统时添加了当前微秒,因此在保存实体时会出现乐观并发异常。

Hence entity framework thinks something else has edited the db since its original value is no longer equal to what is in the db (as the microseconds value is made up on the spot). SQL like the following is produced:

因此实体框架认为其他东西已经编辑了db,因为它的原始值不再等于db中的内容(因为微秒值是在现场组成的)。生成以下SQL:

exec sp_executesql N'UPDATE [dbo].[Profiles] SET [DOB] = @0, [TotalTime] = @1, [Modified] = @2 WHERE (([Id] = @3) AND ([DOB] = @4)) ',N'@0 datetime2(7),@1 float,@2 datetime2(7),@3 uniqueidentifier,@4 datetime2(7)',@0='2015-06-22 15:21:43.4180000',@1=3210,@2='2015-06-22 15:22:52.7520000',@3='F944965E-9E18-E511-BF26-4CEB4272XXXX',@4='2015-06-22 15:21:01.5320000'

exec sp_executesql N'UPDATE [dbo]。[Profiles] SET [DOB] = @ 0,[TotalTime] = @ 1,[Modified] = @ 2 WHERE(([Id] = @ 3)AND([DOB] = @ 4))',N'@ 0 datetime2(7),@ 1 float,@ 2 datetime2(7),@ 3 uniqueidentifier,@ 4 datetime2(7)',@ 0 ='2015-06-22 15:21: 43.4180000',@ 1 = 3210,@ 2 ='2015-06-22 15:22:52.7520000',@ 3 ='F944965E-9E18-E511-BF26-4CEB4272XXXX',@ 4 ='2015-06-22 15: 21:01.5320000'

EF is looking for the date 2015-06-22 15:21:01.5320000 however the stored date is in fact 2015-06-22 15:21:01.533. A difference of 1 millisecond.

EF正在寻找2015-06-22 15:21:01.5320000的日期,但实际存储的日期是2015-06-22 15:21:01.533。相差1毫秒。

I'm not sure why this is?

我不确定为什么会这样?

The fix Im presently trying to implement is to add this function into the main.js of my app.

我目前试图实现的修复是将此函数添加到我的应用程序的main.js中。

breeze.DataType.parseDateFromServer = function (source) { var dt = moment(source).toDate(); dt.setMilliseconds(0); return dt; };

breeze.DataType.parseDateFromServer = function(source){var dt = moment(source).toDate(); dt.setMilliseconds(0);返回; };

This seems to have gotten me out of this bind.

这似乎让我摆脱了这种束缚。

1 个解决方案

#1


0  

Doh! As it turned out someone had set the ConcurrencyMode of the DOB field in The entity diagram to 'Fixed' and this caused it to be heavily validated in this way. Changing that back to 'None' fixed it.

卫生署!事实证明有人将实体图中DOB字段的ConcurrencyMode设置为'Fixed',这导致它以这种方式大量验证。将其更改回“无”修复它。

#1


0  

Doh! As it turned out someone had set the ConcurrencyMode of the DOB field in The entity diagram to 'Fixed' and this caused it to be heavily validated in this way. Changing that back to 'None' fixed it.

卫生署!事实证明有人将实体图中DOB字段的ConcurrencyMode设置为'Fixed',这导致它以这种方式大量验证。将其更改回“无”修复它。