3

这是我的查询

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>();

我得到的例外是

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

该查询在管理工作室中运行良好。还有另一种方法我应该使用直接的 sql 查询来避免这个错误吗?

谢谢

4

2 回答 2

2

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})'
于 2013-08-21T04:49:36.770 回答
0

尝试从 SQL 字符串中删除冒号字符。甚至注释中的冒号也会导致此错误。下面的修复是将“Note:”更改为“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);
于 2017-05-26T16:37:03.357 回答