实体框架5,代码第一,全文搜索,但可以通过CreateQuery? [英] Entity Framework 5, Code First, Full Text Search but IQueriable via CreateQuery?
问题描述
我已经读了很多,到目前为止,我的结论是:
-
存储过程和表值函数不能使用代码优先映射。
-
仍然可以使用动态sql来调用它们
dbContext.Database.SqlQuery< Movie>(Sql,参数)
但是这返回IEnumerable我想要IQueryable,以便在从数据库服务器获取数据之前可以进行更多的过滤。我知道我可以把这些参数发送给Db函数,但是我不想这样做。
-
我的需求是来自IObjectContextAdapter的CreateQuery函数,看起来像这样(选择全部只是为了测试):
IQueryable< Movie> result =((IObjectContextAdapter)dbContext).ObjectContext.CreateQuery< Movie>(SELECT * FROM Movie);
-
异常
'System.Data.EntitySqlException未处理
HResult = -2146232006
消息=查询语法无效近期'*',第1行第9列' p>
所以问题是:
-
为什么我得到这个例外,可以修复?
-
如果没有任何方式与Code First做FTS返回IQueryable ?
尝试这样
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查询中的value关键字
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:
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)
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.
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.'
So the questions are:
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 ?
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!