1

I'm trying to work with Entity Framework Core against a SQL Server database.

I've got a test class (based on Microsoft's demo 'blog/post' sample code) which I migrate to a SQL Server database.

I want to add a member to my test class which will save as a SqlGeometry column and allow me to read/write that data.

It doesn't seem that there is an appropriate geometry type in Entity Framework/ .NET Core - so how should I approach the problem?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dave Alger
  • 339
  • 7
  • 23

1 Answers1

2

You can see a workaround here, which will enable you to use this unsupported data type: https://github.com/aspnet/EntityFramework/issues/1100#issuecomment-286362657

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Thise feels like (a very good) half solution in that I can write data to a SqlGeometry column. But I can't see how I can read that data back - since as far as I understand from this (https://learn.microsoft.com/en-us/ef/core/querying/raw-sql) "SQL queries can only be used to return entity types that are part of your model." - and my Geometry point isn't a part of the model it's [NotMapped] – Dave Alger Mar 17 '17 at 07:15
  • Correct, as noted in the sample code, you can use the column, but not read it directly, as there is no mapping available - why do you need to read it directly? – ErikEJ Mar 17 '17 at 08:00
  • I'll be passing it out as text in a JSON object. And perhaps using it. But I can just grab it with a SqlConnection and SqlCommand for now, until EF catches up. – Dave Alger Mar 17 '17 at 08:36