Full text + spatial search with Entity Framework 4

落花浮王杯 提交于 2019-12-08 05:42:16

问题


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.


回答1:


You certainly can write a proc which returns entity types. Indeed, in EF 1 that was the only option for procs. The proc returns a set of values, not a table, but I can't see that you actually need this.

You can also do free-form T-SQL in EF 4 using Context.ExecuteStoreQuery.




回答2:


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.



来源:https://stackoverflow.com/questions/2730944/full-text-spatial-search-with-entity-framework-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!