获取分组记录时记录未检索为小数精度损失

Records not retriving as decimal precision lost when getting grouped records

我们有一个使用 Linq to SQL 的项目。分组后,不从与分组Key相关的表中选择记录。 运行 探查器帮助发现在检索记录时添加的条件对小数字段的精度较低。解决方案是什么?

var  groupedSO = from so in db.SalesOrders
                 orderby so.BizDate, so.POSID ascending
                 where SalesOrders.Contains(so.POSID)                                                
                 group so by 
                 new
                 {
                     so.BizDate.Value.Date,                                                      
                     so.CurrRateMultp, //Decimal: Value in DB is 0.33333333                                                        
                 }
                 into grps
                 select grps;

当我们遍历组时,

 foreach (var orders in groupedSO)
  {
    foreach (var order in orders)
      {
        //No records available
      }
  }

它使用类似于

的SQL选择记录
select <Fields> 
from Table 
where CONVERT(DATE, [t0].[bizdate])  = @P0 AND  @x4 = [t0].[currratemultp]

但在 SQL 中生成的 @x4=0.3333 的值,而在 DB 中的值是 0.33333333

这会导致无法检索记录。

字段以简单的方式映射

[Column]
public decimal? CurrRateMultp { get; set; }

SQL中的字段类型是

decimal(19, 8)

请帮助增加精度需要进行哪些更改。

感谢所有检查此内容的人,

我明白了。有一个命名参数 DbType for the ColumnAttribute。尽管微软网站说

Use this property to specify the exact text that defines the column in a Transact-SQL table declaration. Specify the DbType property only if you plan to use CreateDatabase to create an instance of the database. The default value of DbType is inferred from the member type. For more information, see SQL-CLR Type Mapping.

将此设置为 SQL 类型有助于我获得精度。 所以,我宣布我的 属性 为

 [Column(DbType = "decimal(19, 8)")]     
 public decimal? CurrRateMultp { get; set; }

这使得SQL生成带有小数点的礼仪。 谢谢大家!希望这对其他人也有帮助。