【发布时间】:2017-10-25 16:19:15
【问题描述】:
我正在使用带有 Entity Framework Core 的 Postgres 数据库。
在我的数据库中,Price 表有 price(numeric) 列,并且存储了诸如 12345.123456789012345678901234567890 之类的值,即(高精度)
当我使用 LINQ 查询获取数据时,每次我得到错误:
"System.OverflowException: 数值不适合 System.Decimal"
我在 DbContext 的 OnModelCreating() 方法中找到了将 Property.HasColumnType("decimal(20,5)") 用于数据库列的方法,但它不起作用。另外,我看到在 edmx 文件中定义选择查询,但 Entity Framework Core 不生成 edmx 文件。
那么,我们如何在 C# 中使用 Entity Framework Core 为 Postgres 的数值数据类型定义精度? (注:精度可以减少到小数点后至少5位)
【问题讨论】:
-
你的 linq 查询是什么
-
什么是模型属性价格数据类型?
-
linq 查询:dBContext.PriceTable.Where(x => x.id == 2).First().Value;
-
价格数据类型为数字
-
numeric 是 sql DataType ,什么是 Frontend dataType decimal ,int ,float, and double
标签: c# postgresql linq entity-framework-core