全文+实体框架空间搜索4 [英] Full text + spatial search with Entity Framework 4
问题描述
- RestaurantId
- 名称
- 纬度
- 经度
我想让用户按名称搜索餐馆和/或地址。如何编写LINQ查询来支持?我需要能够支持用户不输入名称或地址的可能性,只需输入名称,地址,名称和地址。
我的初始想法是写一个存储过程来计算两个lat / long对之间的距离和一个用于调用FREETEXTTABLE的表值函数,并在我的查询上使用一些条件加入调用。但是,似乎实体框架4不支持表值函数。
您不能写任何 LINQ
在这个时间点支持地理空间查询 - 不管是$ code> EF 还是 LinqToSql
。这是因为没有可以处理SQL Server中存在的特殊 ST< any>
空间语法的 LINQ
语法(例如 STIntersects(..)
)
您将需要编写存储过程,然后您可以通过 EF
获得访问。
如果您希望返回 Sql GEOGRAPHY
字段在结果中,您将需要返回一个 VARBINARY(MAX)
我认为是等效字段类型为 C#
代码。
希望帮助。
Let's say I have a SQL 2005 database with a table called Restaurants. The Restaurants table has the following columns:
- RestaurantId
- Name
- Latitude
- Longitude
I want to let users search for restaurants by name and/or address. How do I write the LINQ query to support this? I need to be able to support the possibility that the user doesn't enter in a name or address, just the name, just the address, or both name and address.
My initial idea was to write a stored procedure to calculate the distance between two lat/long pairs and a table value function for calling FREETEXTTABLE and using some conditional Join calls on my query. However, it appears that Entity Framework 4 doesn't support table value functions.
You cannot write any LINQ
that supports geospatial queries at this point of time - be it EF
or LinqToSql
. This is because there is no LINQ
syntax which can handle the special ST<whatever>
spatial syntax that exists in SQL Server 2008. (eg. STIntersects(..)
)
You will need to write a Stored Procedure which you can then get access to via EF
.
If you wish to return a Sql GEOGRAPHY
field in a result, you will need to return a VARBINARY(MAX)
i think as the equivalent field type for the C#
code.
Hope This Helps.
这篇关于全文+实体框架空间搜索4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!