Reputation: 1317
I would like to be able to use Full text search in Code First Entity Framework. However this is not the only SQL specific function the team I'm in will be likely to use in the future.
I know that Code First isn't supposed to do database specific stuff or UDFs.
However if I can't get this working I will have slow queries. I want to be able to search through a large number of records (millions) based on a number of criteria including date ranges, partial text search and boolean fields.
So ideally I would be able to on the fly change the name of the table that a particular DataSet
ends up querying to be dbo.GetMyEntityName(queryString)
. I don't think there is a way to do this, I thought of replacing it before it was sent to the sql server but even I managed that I would have to know which reference to the table it was.
I tried looking into how EFProviderWrappers
handles it, but it doesn't handle code first very well and I really don't have the spare time at the moment to write a new version for Code First. I don't know if it is even possible which part of the command to replace in there, I wasn't able to get it working at all. Although I didn't try running it with an edmx.
The other thing I thought of was using the IQueryable.ToString
method which for my DbQueries
return SQL wrapping that with a select * from ({0}) where {1}
and then executing it using Context.Database.SqlQuery
the problem with that entity framework was confused between my ViewModels
and my Domain objects because in some cases they had similar or the same name.
Another solution was to Register a search/replace with a custom SqlConnection
, so once it's registered, the next select gets edited, so something like [dbo].[MyEntity]
gets replaced with [dbo].GetMyEntity('query')
. However that's very limited, if you wanted to refer to the same table multiple times in the same query then it would replace both, the first or the last... which isn't very flexible. If I could find out how it decides to alias these tables then it would be very easy to do this method.
Any ideas would be greatly appreciated.
Upvotes: 0
Views: 387
Reputation: 364319
Seriously. The idea is not using EF in such situation - use SQL directly because you knows name of your tables (you are defining the mapping). As you can see EF has serious disadvantages in your scenario because it is targeted to smaller (less performance) critical applications.
This immaturity gap can be improved after .NET 4.5 release where table-valued functions will be supported directly (but only when using EDMX).
Upvotes: 1