I trying to store the Latitude and Longitude to my Database.
I have My column type in DB as
[Latitude] NUMERIC (12, 8) NULL,
[Longitude] NUMERIC (12, 8) NULL,
In C# Model my Properties are
[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; }
I want to store this Latitude and Longitude value to my Database table
What am doing wrong here please help
decimal lats = decimal.Parse("56.12345678");
decimal longs = decimal.Parse("10.18732210");
context.test.Add(new test
{
Latitude = lats,
Longitude = longs
});
context.SaveChanges();
it stores Like in DB
Like This
Latitude: 56.12000000 and Longitude : 10.18000000
I want the Same Value to be stored in DB
"56.12345678" and "10.18732210";
>Solution :
You probably need to specify it also in your OnModelCreating like this:
modelBuilder.Entity<Test>().Property(a => a.Latitude).HasPrecision(18, 9);
modelBuilder.Entity<Test>().Property(a => a.Longitude).HasPrecision(18, 9);
Just in case you need more advanced features and you are using EF Core take a look at:
https://docs.microsoft.com/en-us/ef/core/modeling/spatial