Skip to content

Commit b504ed3

Browse files
committed
Fix failing HQL test
1 parent 443ac97 commit b504ed3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

NHibernate.Spatial.MsSql/Dialect/MsSql2008FunctionRegistration.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,23 @@ public virtual SqlString GetSpatialRelationString(object geometry, SpatialRelati
382382
return GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion);
383383

384384
default:
385-
return new SqlStringBuilder(8)
386-
.AddObject(geometry)
387-
.Add(".ST")
388-
.Add(relation.ToString())
389-
.Add("(")
390-
.AddObject(anotherGeometry)
391-
.Add(")")
392-
.Add(criterion ? " = 1" : "")
393-
.ToSqlString();
385+
// NOTE: Cast is only required if "geometry" is passed in as a parameter
386+
// directly, rather than as a column name. This is because parameter
387+
// will be passed as binary and SQL Server can't call methods on
388+
// binary data.
389+
return new SqlStringBuilder()
390+
.Add("CAST(")
391+
.AddObject(geometry)
392+
.Add(" AS ")
393+
.Add(sqlTypeName)
394+
.Add(")")
395+
.Add(".ST")
396+
.Add(relation.ToString())
397+
.Add("(")
398+
.AddObject(anotherGeometry)
399+
.Add(")")
400+
.Add(criterion ? " = 1" : "")
401+
.ToSqlString();
394402
}
395403
}
396404

0 commit comments

Comments
 (0)