Controller Model on Asp .Net Core Api
scsJames opened this issue · 5 comments
Hello, i try to create an Controller to post and get data using .Net Core Api ( .Net 6 ) ... when i try to post or get data an error an error is occured :
( This message error is from Postman )
System.InvalidOperationException: The property 'Geofence.Coordinates' is of type 'Point' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger
1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.Validate(IModel model, IDiagnosticsLogger
1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
there is a way to fix this please ?
The idea is to use Controller to create and get points and polygons
Best Regard's
Seems you're trying to store the point directly in the sql server.
Would suggest to store the lat and lon seperately in two different fields in the database.
In sql server i created a field of type geometry that will store spatial data as SQL Server documentation ..
Will try the way you told me looks good
Using this way i need to add fiels for each type of model : point, polygon ... on table in sql server ?
if you could tell me about hte way i can store Polygon on Sql Server using this amazing Library, i founded it very powerful and easy just i need to know how i can store Points, Polygon in SQL Server using Entity Framework ( .NET 6 )
Sorry I didn't use sql server for a long time. However I can take a quick search and back to you.
Hi @scsJames , hope the following doc from microsoft could help:
https://docs.microsoft.com/en-us/ef/core/modeling/spatial
Please notice that the Point
class which you can serialize or deserialize from sql server is different from the Point
class in our library. You need to write some helper class to do the conversion and please remember to use the Point
class from sql in the entity class you want to save to sql server.