如何使c#十进制匹配EF更改跟踪的SQL十进制? [英] How can I make a c# decimal match a SQL decimal for EF change tracking?

查看:106
本文介绍了如何使c#十进制匹配EF更改跟踪的SQL十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为避免触及EF中的无变化记录,原始和当前实体值匹配非常重要。我看到小数点的问题,其中EF实体具有SQL表示,并且正在与c#decimal进行比较。

To avoid touching changeless records in EF it's important that original and current entity values match. I am seeing a problem with decimals where the EF entity has SQL representation and that is being compared to c# decimal.

例如:在EF中,我的记录可能是0.00但是值正在更新是EF。检测到这是一个变化。

For Example: In EF my record might be 0.00 but the value am updating with is 0. EF detects this as a change.

另一个例子:在EF我的记录可能是0.87但是值是0.872然后我希望这是相同的值并且记录未经修改。 EF也会将此检测为更改。

Another Example: In EF my record might be 0.87 but the value is 0.872 then I would expect this to be the same value and the record unmodified. EF detects this as a change also.

使用c#decimal时如何确保原始值和当前值匹配?

How can I ensure that original and current values match when using c# decimal?

也许有办法在更新之前将c#decimal转换为实体(SQL)十进制?

Maybe there is a way to turn the c# decimal into an entity (SQL) decimal before the update?

推荐答案

您好jwrightmail,

Hi jwrightmail,

从以下文档中,我们知道.Net框架的十进制映射的数据类型是十进制。

From the following document, we know that the datatype of decimal mapping to .Net framework is decimal.

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings

>>使用c#decimal时如何确保原始值和当前值匹配?

>>How can I ensure that original and current values match when using c# decimal?

请提供更多信息可以重现问题的信息,例如相关的代码段。

Could you please provide a bit more information which could reproduce the issue, such as related code snippet.

祝你好运,

张龙

这篇关于如何使c#十进制匹配EF更改跟踪的SQL十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆