3

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 ?

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
borisdj
  • 2,201
  • 3
  • 24
  • 31
  • Just to update answer: My post(at the moment it is the last one) on the following topic: [a-composable-full-text-search-with-a-code-first-model](http://stackoverflow.com/questions/18746127/a-composable-full-text-search-with-a-code-first-model/20744678#20744678) – borisdj Dec 23 '13 at 13:45

1 Answers1

2

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

Community
  • 1
  • 1
NSGaga-mostly-inactive
  • 14,052
  • 3
  • 41
  • 51