【发布时间】:2019-09-26 08:06:27
【问题描述】:
不能在 SQL 中存储十进制值。 想像十进制(2,8)一样存储
点赞 32.12345678
[Column(TypeName = "decimal(2,8)")]
[Display(Name = "Latitude")]
public decimal Latitude { get; set; }
在 NuGet 控制台中
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [DredgingDatas] (
[Id] int NOT NULL IDENTITY,
[DredgerId] int NOT NULL,
[DredgingTime] datetime2 NOT NULL,
[Density] decimal NOT NULL,
[Velocity] decimal NOT NULL,
[Production] decimal NOT NULL,
[Latitude] decimal(2, 8) NOT NULL,
[Longitude] decimal(2, 8) NOT NULL,
[Tide] decimal NOT NULL,
[DredgeHead] float NOT NULL,
CONSTRAINT [PK_DredgingDatas] PRIMARY KEY ([Id]),
CONSTRAINT [FK_DredgingDatas_Dredgers_DredgerId] FOREIGN KEY ([DredgerId]) REFERENCES [Dredgers] ([DredgerId]) ON DELETE CASCADE
);
The scale (8) for column 'Latitude' must be within the range 0 to 2.
【问题讨论】:
-
错误很明显 - 值的顺序错误。使用
(8,2)。两位数对坐标没有意义,你可能想要(10,8) -
另一方面,如果您想执行空间搜索,您可能需要使用 SQL Server 的空间几何或地理类型
-
decimal(p,s)规范中逗号前的数字是数字中的总位数,因此要存储您的样本编号,您需要使用decimal(10,8) -
感谢您的帮助,成功了。但这次我不需要空间数据库。
标签: sql sql-server entity-framework