3

I'm looking at using the new Geography types in Entity Framework 5 and 6 for my next project - see this tutorial link http://msdn.microsoft.com/en-us/data/jj250903.aspx

I've created a MyProject.Entities Visual Studio library project containing my entity models. The problem that I foresee is that I would need to reference Entity Framework 5+ in the MyProject.Entities project in order to use the DbGeography type that corresponds to the geography column in my SQL Server database when mapping this using Entity Framework (or at least that appears to be the case based on the instructions in the tutorial link above). I'd prefer not to directly reference the Entity Framework in my MyProject.Entities project since I'm planning to share this library across several project which may be using different versions of Entity Framework. In terms of style, I'd also like to keep the MyProject.Entities project as simple and clean as possible - coupling my entities project to the Entity Framework seems ugly by this criteria.

Here is a simplified example of one of my models:

namespace MyProject.Entities
{
    public class PointOfInterest
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DbGeography Geo { get; set; }
    }
}

Has anyone else had this concern? If so, how did you get around it?

EDIT: I thought of a good way to articulate my concern. The new OWIN identity model provides interfaces like IUser so that developers can write their own implementations without referencing the Entity Framework directly, e.g. https://code.msdn.microsoft.com/Simple-Aspnet-Identiy-Core-7475a961. Unfortunately DbGeography doesn't seem to implement such an interface http://referencesource.microsoft.com/#System.Data.Entity/System/Data/Spatial/DbGeography.cs so I'm stuck referencing the Entity Framework.

bummi
  • 27,123
  • 14
  • 62
  • 101
Aaron Newton
  • 2,124
  • 1
  • 28
  • 31

1 Answers1

1

Maybe you can just use

Microsoft.SqlServer.Types.SqlGeography

http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.types.sqlgeography.aspx

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Oh boo. I was confident this was the answer. But after mapping the entity to my DataContext I got this error: _error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties PointOfInterest.Geo in Set PointsOfInterests._. The `Geo` property is of type `SqlGeography` and matches the database column name. I looked it up and it appears that Linq to SQL simply doesn't support `SQLGeography` - http://stackoverflow.com/a/2846053/201648. There is an a SQL Server UDF implementation to solve the problem on the same thread - http://stackoverflow.com/a/2968633/201648 – Aaron Newton Dec 08 '14 at 11:27
  • 1
    If you must acssociate your class with EF, you must use DbGeography – ErikEJ Dec 08 '14 at 11:31
  • Thank you ErikEJ. Will mark as the answer on the basis of the above comment. – Aaron Newton Dec 08 '14 at 11:32