Go to SoftFluent site to register or reset your account
Welcome Guest Search | Active Topics | Log In

SQL Server 2008 / Geography type Options
NetConsulting
#1 Posted : Monday, November 02, 2009 2:35:01 PM
Rank: Member

Groups: Users

Joined: 8/13/2009
Posts: 10
Hi

Is there a mapping between the SQL geography type and the CLR SqlGeography type ?

Regards
Mona
#2 Posted : Friday, November 06, 2009 11:22:34 AM
Rank: Newbie

Groups: Users

Joined: 10/26/2009
Posts: 3
Hi,
There isn’t a Geography type in CodeFluent yet.
If you have a general question about mapping between the SQL geography type and the CLR SqlGeography type, look at the following link:
http://sqlblogcasts.com/blogs/simons/archive/2009/02/22/Converting-Mappoint-routes-to-SqlGeography.aspx

This article is about Converting Mappoint routes to SqlGeography.
I hope it will help you.

Mona
CodeFluent Support Team
#3 Posted : Wednesday, November 18, 2009 7:20:34 PM
Rank: Administration


Groups: Users, Registered, CodeFluent

Joined: 8/11/2009
Posts: 69
Hi,

Although there is not a geography type in CodeFluent (as this is too specific to SQL Server 2008), you can still use the new SQL 2008 geography type today.

First you need to declare the target type in the CodeFluent Sql Server Producer (with the 'cfps:dataType' attribute). Then, optionally, you can declare a computed companion property that will hold the data as the corresponding Sql Server 2008 .NET Type: SqlGeography.

It will work because these types can be transferred back and forth as arrays of bytes. Here is a sample model that does it:

Code:

<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultNamespace="Test" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1">

<Address>
  <Id />
  <RawSpatialLocation cfps:dataType="geography" typeName="byte[]" maxLength="-1" />
  <SpatialLocation typeName="Microsoft.SqlServer.Types.SqlGeography" persistent="false">
    <cf:rule typeName="OnGet" />
    <cf:rule typeName="OnAfterSet" />
    <cf:snippet name="SpatialLocation">
    private void OnGetSpatialLocation()
    {
        _spatialLocation = new Microsoft.SqlServer.Types.SqlGeography();
        using (System.IO.MemoryStream stream = new System.IO.MemoryStream(RawSpatialLocation))
        {
            using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
            {
                _spatialLocation.Read(reader);
            }
        }
    }

    private void OnAfterSetSpatialLocation(Microsoft.SqlServer.Types.SqlGeography spatialLocation)
    {
        using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
        {
            using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream))
            {
                _spatialLocation.Write(writer);
                _rawSpatialLocation = stream.ToArray();
            }
        }
    }
    </SpatialLocation>
</Address>
</cf:project>


NOTE1: make sure Microsoft.SqlServer.Types.dll is referenced for the project to compile.
NOTE2: all this is valid for the SqlGeography, SqlGeometry and SqlHierarchyId types.

The next version of CodeFluent will allow you to directly declare this:
UPDATE: 2009/12/18 the today build has it now!

Code:

<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultNamespace="Test" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" assemblyPaths="c:\temp\Microsoft.SqlServer.Types.dll"> <!-- adapt this to your machine -->

<Address>
  <Id />
  <SpatialLocation cfps:dataType="geography" typeName="Microsoft.SqlServer.Types.SqlGeography, Microsoft.SqlServer.Types" />
</Address>
</cf:project>


Thanks for supporting us :)

CodeFluent Support Team
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.301 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.064 seconds.