<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Spatial data and Entity Framework &#8211; from real world usage</title>
	<atom:link href="http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/</link>
	<description>Taking something that can&#039;t be done, and then doing it.</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:02:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: cincura.net</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-5855</link>
		<dc:creator>cincura.net</dc:creator>
		<pubDate>Thu, 16 Jun 2011 08:46:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-5855</guid>
		<description>Wondering whether it&#039;s possible to index computed spatial column in MS SQL...</description>
		<content:encoded><![CDATA[<p>Wondering whether it&#8217;s possible to index computed spatial column in MS SQL&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Davis</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-5854</link>
		<dc:creator>Kirk Davis</dc:creator>
		<pubDate>Thu, 16 Jun 2011 08:39:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-5854</guid>
		<description>I used a variation on the same work-around, with some differences being that, since this app doesn&#039;t (currently) ever have updates directly to the SQL geography column, I made that column a computed column, instead of using a trigger (I don&#039;t particularly like using triggers unless I have to).  Also, instead of using the LatLong structure, I just appended to public properties to my entity class, GeoLat() and GeoLong().   The getter just returns the lat (or long) portion of the coordinate, and the setter updates that portion of the coordinate (and then converts the coordinate back to byte[], in order to update the actual column).

For my SQL geography computed column, I used the same as from your trigger ( [geography]::STGeomFromWKB([CenterPointBytes],(4326)) ). 

As an example, here is my GeoLat property (in VB.Net):
    
    Public Property GeoLat As Double?
        Get
            If CenterPointBytes Is Nothing Then
                Return New Nullable(Of Double)(Nothing)
            Else
                Return Math.Round(SqlGeography.STGeomFromWKB(New SqlBytes(CenterPointBytes), 4326).Lat.Value, 5)
            End If
        End Get
        Set(ByVal value As Double?)
            If value.HasValue AndAlso value  0 Then
                Dim oldGeo As SqlGeography = SqlGeography.STGeomFromWKB(New SqlBytes(CenterPointBytes), 4326)
                If CenterPointBytes Is Nothing OrElse oldGeo.IsNull OrElse oldGeo.Long.IsNull Then
                    Dim newGeo As SqlGeography = SqlGeography.STPointFromText(New SqlChars(New SqlString(String.Format(&quot;POINT({0} {1})&quot;, 0, value))), 4326)
                    CenterPointBytes = newGeo.STAsBinary().Value
                Else
                    Dim sqlGeo As SqlGeography = SqlGeography.STPointFromText(New SqlChars(New SqlString(String.Format(&quot;POINT({0} {1})&quot;, oldGeo.Long, value))), 4326)
                    CenterPointBytes = sqlGeo.STAsBinary().Value
                End If
            End If
        End Set
    End Property</description>
		<content:encoded><![CDATA[<p>I used a variation on the same work-around, with some differences being that, since this app doesn&#8217;t (currently) ever have updates directly to the SQL geography column, I made that column a computed column, instead of using a trigger (I don&#8217;t particularly like using triggers unless I have to).  Also, instead of using the LatLong structure, I just appended to public properties to my entity class, GeoLat() and GeoLong().   The getter just returns the lat (or long) portion of the coordinate, and the setter updates that portion of the coordinate (and then converts the coordinate back to byte[], in order to update the actual column).</p>
<p>For my SQL geography computed column, I used the same as from your trigger ( [geography]::STGeomFromWKB([CenterPointBytes],(4326)) ). </p>
<p>As an example, here is my GeoLat property (in VB.Net):</p>
<p>    Public Property GeoLat As Double?<br />
        Get<br />
            If CenterPointBytes Is Nothing Then<br />
                Return New Nullable(Of Double)(Nothing)<br />
            Else<br />
                Return Math.Round(SqlGeography.STGeomFromWKB(New SqlBytes(CenterPointBytes), 4326).Lat.Value, 5)<br />
            End If<br />
        End Get<br />
        Set(ByVal value As Double?)<br />
            If value.HasValue AndAlso value  0 Then<br />
                Dim oldGeo As SqlGeography = SqlGeography.STGeomFromWKB(New SqlBytes(CenterPointBytes), 4326)<br />
                If CenterPointBytes Is Nothing OrElse oldGeo.IsNull OrElse oldGeo.Long.IsNull Then<br />
                    Dim newGeo As SqlGeography = SqlGeography.STPointFromText(New SqlChars(New SqlString(String.Format(&#8220;POINT({0} {1})&#8221;, 0, value))), 4326)<br />
                    CenterPointBytes = newGeo.STAsBinary().Value<br />
                Else<br />
                    Dim sqlGeo As SqlGeography = SqlGeography.STPointFromText(New SqlChars(New SqlString(String.Format(&#8220;POINT({0} {1})&#8221;, oldGeo.Long, value))), 4326)<br />
                    CenterPointBytes = sqlGeo.STAsBinary().Value<br />
                End If<br />
            End If<br />
        End Set<br />
    End Property</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cincura.net</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-5566</link>
		<dc:creator>cincura.net</dc:creator>
		<pubDate>Sat, 30 Apr 2011 05:10:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-5566</guid>
		<description>It doesn&#039;t matter whether it&#039;s public or internal or anything else (from EF&#039;s POV). It&#039;s extension method because of http://blog.cincura.net/id/230897 , but again, it&#039;s just a to make it nicer.

What matters is properly EdmFunction &quot;filled&quot; attribute and you have to have this SP imported in model, of course.</description>
		<content:encoded><![CDATA[<p>It doesn&#8217;t matter whether it&#8217;s public or internal or anything else (from EF&#8217;s POV). It&#8217;s extension method because of <a href="http://blog.cincura.net/id/230897" rel="nofollow">http://blog.cincura.net/id/230897</a> , but again, it&#8217;s just a to make it nicer.</p>
<p>What matters is properly EdmFunction &#8220;filled&#8221; attribute and you have to have this SP imported in model, of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: remi</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-5564</link>
		<dc:creator>remi</dc:creator>
		<pubDate>Fri, 29 Apr 2011 23:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-5564</guid>
		<description>Thanks!  What a slick solution.

I&#039;m trying to get it to work, but my [EdmFunction] isn&#039;t happy.

I don&#039;t understand ... it looks like Distance() is an extension method, but it&#039;s internal?  My compiler doesn&#039;t like that.  I made it public and put it in a public static class and it compiles, but I get:

System.NotSupportedException: The specified method &#039;Int32 Distance(Byte[], Byte[])&#039; on the type &#039;MyApp.DistanceExtension&#039; cannot be translated into a LINQ to Entities store expression.

:(  My database has the function and everything else ...</description>
		<content:encoded><![CDATA[<p>Thanks!  What a slick solution.</p>
<p>I&#8217;m trying to get it to work, but my [EdmFunction] isn&#8217;t happy.</p>
<p>I don&#8217;t understand &#8230; it looks like Distance() is an extension method, but it&#8217;s internal?  My compiler doesn&#8217;t like that.  I made it public and put it in a public static class and it compiles, but I get:</p>
<p>System.NotSupportedException: The specified method &#8216;Int32 Distance(Byte[], Byte[])&#8217; on the type &#8216;MyApp.DistanceExtension&#8217; cannot be translated into a LINQ to Entities store expression.</p>
<p> <img src='http://blog.cincura.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   My database has the function and everything else &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-2657</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Thu, 22 Apr 2010 23:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-2657</guid>
		<description>Cincura, 

Thanks for the solution. I didn&#039;t know we could do that in EF. It&#039;s good to know about the functions. 

In this case, to take advantage of indexes you could just write the query using dynamica SQL. 
context.CreateQuery(&quot;SELECT bla from X where ...&quot;, param1,param2);
This is probably not as elegant, but in this case I would go for the performant version. 

Also I know that it&#039;s hard to support and MS might be thinking of 3rd party DBs, but NHibernate has a really good support for UserTypes that works well accross different DBs, so well that they even support SqlSpatial and queries on top of it :)</description>
		<content:encoded><![CDATA[<p>Cincura, </p>
<p>Thanks for the solution. I didn&#8217;t know we could do that in EF. It&#8217;s good to know about the functions. </p>
<p>In this case, to take advantage of indexes you could just write the query using dynamica SQL.<br />
context.CreateQuery(&#8220;SELECT bla from X where &#8230;&#8221;, param1,param2);<br />
This is probably not as elegant, but in this case I would go for the performant version. </p>
<p>Also I know that it&#8217;s hard to support and MS might be thinking of 3rd party DBs, but NHibernate has a really good support for UserTypes that works well accross different DBs, so well that they even support SqlSpatial and queries on top of it <img src='http://blog.cincura.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cincura.net</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-2526</link>
		<dc:creator>cincura.net</dc:creator>
		<pubDate>Mon, 22 Mar 2010 08:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-2526</guid>
		<description>The problem is, that EF isn&#039;t just for MS SQL, but for 3rd party database engines as well. So the spatial data support isn&#039;t easy, especially the datatypes mapping. 

And BTW OT the MS SQL spatial data support is a good average, nothing super ultra great. At least IMO.</description>
		<content:encoded><![CDATA[<p>The problem is, that EF isn&#8217;t just for MS SQL, but for 3rd party database engines as well. So the spatial data support isn&#8217;t easy, especially the datatypes mapping. </p>
<p>And BTW OT the MS SQL spatial data support is a good average, nothing super ultra great. At least IMO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: turtlewax</title>
		<link>http://blog.cincura.net/231242-spatial-data-and-entity-framework-from-real-world-usage/#comment-2524</link>
		<dc:creator>turtlewax</dc:creator>
		<pubDate>Sun, 21 Mar 2010 17:15:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cincura.net/?p=231242#comment-2524</guid>
		<description>1st, your suggestions are very helpful and appreciated. If someone is implementing a basic &quot;cup holder&quot; spatial widget, these work-arounds get the job done nicely.

For anyone doing serious spatial work, I&#039;ve concluded that the Entity Framework is a complete load of bull.  I&#039;ve exhaustively tested all the proposed work-arounds. 

SQL Server spatial performs great.  But the Entity Framework (for spatial)  is a dead-end, and will remain a dead-end until MS fixes it.</description>
		<content:encoded><![CDATA[<p>1st, your suggestions are very helpful and appreciated. If someone is implementing a basic &#8220;cup holder&#8221; spatial widget, these work-arounds get the job done nicely.</p>
<p>For anyone doing serious spatial work, I&#8217;ve concluded that the Entity Framework is a complete load of bull.  I&#8217;ve exhaustively tested all the proposed work-arounds. </p>
<p>SQL Server spatial performs great.  But the Entity Framework (for spatial)  is a dead-end, and will remain a dead-end until MS fixes it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

