Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

entity framework - .NET 4.5 Beta DbGeography NotImplementedException

I have a brand new server which I installed the .NET 4.5 Beta redistributable on. I am getting a NotImplemented exception when trying to use the spatial features. This code...

var x = DbGeography.PointFromText(string.Format("POINT({0} {1})", -45, 45), 4326);

Throws this exception...

System.NotImplementedException: The method or operation is not implemented.
at System.Data.Spatial.DefaultSpatialServices.GeographyPointFromText(String geographyText, Int32 spatialReferenceSystemId)

If I install the full VS.NET 11 Beta then the code works fine. Any ideas why? What is missing?

UPDATE FOR ANSWER

Thanks to Pawel. You need to have the SQL CLR Types installed. You can get the 2012 version at this link:

Microsoft? System CLR Types for Microsoft? SQL Server? 2012 http://www.microsoft.com/download/en/details.aspx?id=29065

OPINION

I really dont understand why the .NET framework has a dependency on SQL Server. There is nothing special about these classes. I realize this is likely a historical thing where the code was originally written by the SQL team and the .NET team wanted to reuse it. It's not very clear that this is a provider-based implementation either. A better exception message would have saved a day's work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DefaultSpatialServices in Entity Framework are using SqlGeography and SqlGeometry types as backing types. These two types live in Microsoft.SqlServer.Types.dll assembly that is not part of the .NET Framework. The exception is thrown when EF cannot find these types (the exception could be more helpful...). When you install Visual Studio it will install localdb on your machine (or you may already have a SqlExpress database) and this is probably the way how you got the type on the machine that is working. On a machine where there is only .NET Framework installed and not Sql Server you won't have these types. You can either install SqlExpress on the box where you get the exception or you can try installing just the types. I am not sure where to get the assembly itself but I think the Sql Server feature pack (http://www.microsoft.com/en-us/download/details.aspx?id=27596) may have it. Types from SqlServer 2008 and SqlServer 2012 are supported so it should not matter which version you install.

EDIT

In EF6 the exception will contain a better message see: https://entityframework.codeplex.com/SourceControl/changeset/b3eca2c141c0fb517504f9731dc8ba7a9c5727ee

Work item used to track this bug: https://entityframework.codeplex.com/workitem/3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...