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