实体框架5,代码优先,全文搜索,但通过CreateQuery IQueryable? [英] Entity Framework 5, Code First, Full Text Search but IQueryable via CreateQuery?
问题描述
我使用Code First方法使用.NET 4.5和EF 5,现在我需要实现全文搜索。
我已经阅读了很多内容,到目前为止,我的结论是:
-
存储过程和表值函数不能使用Code First映射。
em> dbContext.Database.SqlQuery< Movie>(Sql,parameters)
但是这会返回IEnumerable我想要IQueryable,这样我可以在从数据库服务器获取数据之前做更多的过滤。我知道我可以将这些参数发送给Db函数,但我不想那样做。
-
我发现可以实现我的需求是IObjectContextAdapter的CreateQuery函数,看起来像这样(全选仅用于测试):
$ b IQueryable< Movie> result =((IObjectContextAdapter)dbContext).ObjectContext.CreateQuery< Movie>(SELECT * FROM Movie); 然而执行这个抛出异常 -
为什么我得到这个异常并且可以修复它?
如果不是的话,Code First有没有办法做FTS来返回IQueryable 试试看这样 Stored procedures nor Table Value Functions can not be mapped with Code First.
Still I can call them using dynamic sql
dbContext.Database.SqlQuery<Movie>(Sql, parameters)
What I have found that could fulfill my needs is CreateQuery function from IObjectContextAdapter that looks like this(Select All just for test):
IQueryable<Movie> result = ((IObjectContextAdapter)dbContext).ObjectContext.CreateQuery<Movie>("SELECT * FROM Movie");
However executing this throws Exception" 'System.Data.EntitySqlException was unhandled HResult=-2146232006 Message=The query syntax is not valid. Near term '*', line 1, column 9.'
Why do I get this exception and can it be fixed ?
If not is there any way with Code First to do FTS that returns IQueryable ?
System.Data.EntitySqlException未处理
HResult = -2146232006
消息=查询语法无效近期'*',第1行第9列'
所以问题是:
$ ul
ObjectQuery< Movie> query =
objectContext.CreateQuery< Movie>(@SELECT VALUE movie FROM Movies);
至于为什么
查看这些链接
与Transact-SQL的差异与Transact-SQL不同,实体SQL不支持
sup端口在SELECT子句中使用*参数。相反
实体SQL参考 - SELECT
SELECT VALUE - LINQ / Entity Framework查询中的值关键字
I am using .NET 4.5 and EF 5 with Code First approach and now I need to implement Full Text Search. I have already read a lot about it and so far my conclusions are:
But this returns IEnumerable and I want IQueryable so that I can do more filtering before fetching the data from db server. I know I can send those parameters to Db function but I don't want that.
So the questions are:
Try it like this
ObjectQuery<Movie> query =
objectContext.CreateQuery<Movie>(@"SELECT VALUE movie FROM Movies");
As for why
see these links
Differences from Transact-SQL Unlike Transact-SQL, Entity SQL does not support use of the * argument in the SELECT clause. Instead
Entity SQL Reference - SELECT
"SELECT VALUE" - value keyword in LINQ/Entity Framework query
这篇关于实体框架5,代码优先,全文搜索,但通过CreateQuery IQueryable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!