4

I am being told to use Microsoft.SqlServer.Types for DbGeography in a homework project I have. The homework project is with ASP.NET, and is trying to use a database to do a search on stuff in the db. (The database is supposed to be from a .bak file, but I had to upload a .bacpac file into azure and then connect back to it, since the .bak file keeps saying it's corrupt).

This is a code block that I have been told to put into the Global.asax.cs file:

protected void Application_Start()
{
    // For Spatial types, i.e. DbGeography
    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
    // This next line is a fix that came from:       https://stackoverflow.com/questions/13174197/microsoft-sqlserver-types-version-10-or-higher-could-not-be-found-on-azure/40166192#40166192
    SqlProviderServices.SqlServerTypesAssemblyName = typeof (SqlGeography).Assembly.FullName;

    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}
    

I have looked at the documentation, and the darned thing just says:

Microsoft.SqlServer.Types

Allows you to use SQL Server spatial types on a machine without SQL Server installed. Enables Entity Framework spatial types to be used (DbGeography and DbGeometry).

Which I think just means that this package enables us to use c expression for SQL, but I would like a better explanation. I have no clue what DbGeography and DbGeometry do.

Additionally, I would like to know if this is applicable to an azure-based db, and not just a local db made from a .bak file.

Community
  • 1
  • 1
Katelyn Rule
  • 41
  • 1
  • 4

1 Answers1

9

I have no clue what DbGeography and DbGeometry do.

It's simple. SQL Server has spatial types. .NET does not.

Microsoft.SqlServer.Types is a library you can add to your .NET project to work with SQL Server geography and geometry data types in your .NET project. Without this library you can only read and write SQL Server spatial types by converting them to text in the WKT format.

For most of the other data types supported by SQL Server there's a corresponding .NET type that works. Eg SQL Server has int .NET has System.Int32, etc.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67