Question

This is my query

var selectDinnerByDistance = string.Format(
            @"Select 
                u.ProfileImageUrl as ProfileImageUrl, 
                d.Starter as Starter,
                d.Main as Main,
                d.Dessert as Dessert,
                d.Dry as DryDinner,
                d.[Date] as EventDate,
                l.GeoLoc.STDistance(geography::STGeomFromText('POINT({0} {1})', 4326)) as Distance
                from dbo.Locations l
                join Dinners d on d.LocationId = l.Id
                join Users u on u.Id = d.UserId
                Order by Distance asc
                OFFSET {2} ROWS
                FETCH NEXT {3} ROWS ONLY"
            , lat, lng, skip, take);
var output = _session
     .CreateSQLQuery(selectDinnerByDistance)
     .SetResultTransformer(Transformers.AliasToBean<DinnerListItemDto>())
     .List<DinnerListItemDto>();

And the exception I'm getting is

Not all named parameters have been set: [':STGeomFromText']

The query works fine in management studio. Is there another way that I should be using straight sql queries to avoid this error?

Thanks

Was it helpful?

Solution

As I stated in the comments above. The solution was to rewrite the query in a different way I replaced "geography::STGeomFromText" with

l.GeoLoc.STDistance(@dist.STBuffer(0.2).STAsText()) as Distance

and placed the following at the top of the query

DECLARE @dist AS Geography = 'POINT({0} {1})'

OTHER TIPS

Try removing colon characters from the SQL string. Even colons in comments can cause this error. Below the fix is to change "Note:" to "Note".

string sql = string.Format(@"select o.orderid from order o
    where o.orderid in (1, 2, 3)   -- Note: Orders 1-3 special
    {0} {1};",
    whereDates, orderBy);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top