我試圖將緯度和經度存盤到我的資料庫中。
我的表中有這些列:
[Latitude] NUMERIC(12, 8) NULL,
[Longitude] NUMERIC(12, 8) NULL,
在 C# 模型類中,我的屬性是:
[Column(TypeName = "numeric")]
[Range(-9999.99999999, 9999.99999999)]
public decimal? Latitude { get; set; }
[Column(TypeName = "numeric")]
[Range(-9999.99999999, 9999.99999999)]
public decimal? Longitude { get; set; }
我想將這些Latitude和Longitude值存盤到我的資料庫表中。
我在這里做錯了什么?請幫忙
decimal lats = decimal.Parse("56.12345678");
decimal longs = decimal.Parse("10.18732210");
context.test.Add(new test
{
Latitude = lats,
Longitude = longs
});
context.SaveChanges();
它將值存盤在資料庫表中,如下所示:
Latitude: 56.12000000
Longitude : 10.18000000
我希望將相同的值存盤在資料庫中:
"56.12345678"
"10.18732210"
uj5u.com熱心網友回復:
您可能還需要在 OnModelCreating 中指定它,如下所示:
modelBuilder.Entity<Test>().Property(a => a.Latitude).HasPrecision(18, 9);
modelBuilder.Entity<Test>().Property(a => a.Longitude).HasPrecision(18, 9);
以防萬一您需要更多高級功能并且正在使用 EF Core,請查看:https : //docs.microsoft.com/en-us/ef/core/modeling/spatial
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/407661.html
標籤:
