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.

2
  • 2
    Maybe just use msdn.microsoft.com/en-us/library/… instead Commented Dec 7, 2014 at 14:08
  • Thank you ErikEJ, that looks very promising. I'll try it out. Commented Dec 7, 2014 at 20:48

1 Answer 1

1

Maybe you can just use

Microsoft.SqlServer.Types.SqlGeography

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 - stackoverflow.com/a/2846053/201648. There is an a SQL Server UDF implementation to solve the problem on the same thread - stackoverflow.com/a/2968633/201648
If you must acssociate your class with EF, you must use DbGeography
Thank you ErikEJ. Will mark as the answer on the basis of the above comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.