|
Article relates to
|
Telerik OpenAccess ORM
|
|
Created by
|
Ralph Waldenmaier
|
|
Last modified
|
April 06, 2012
|
|
Last modified by
|
Pencho Popadiyn
|
DESCRIPTION
The various backends that are supported by Telerik OpenAccess ORM have several database specific features that are accessible for the user through specific SQL statements. These statements could usually not be executed with LINQ expressions. In this article we will look into some commonly used backends, to execute a sql statement that uses the full text search capabilities of the respective backend.
SOLUTION
Each backend has its own syntax and mechanisms to provide the full text search features and we need to be able to execute these statements. Since there is no solution provided with LINQ out of the box, Telerik OpenAccess ORM offers an extension method called SQL, which allows us to insert our own specific sql-code to the resulting sql statement produced by the runtime.
The SQL extension method is in the Telerik.OpenAccess namespace.
MS SQL Server
For SQL Server, the
CONTAINS function can be used to do a full text search query.
Assume that we want to execute the following SQL statement:
Since, as mentioned earlier, there is no contains() method with the same meaning in LINQ as in SqlServer, we need to use the SQL extension method as shown with the following snippet.
The string, which is prepended before the SQL extension method, will be added to the generated sql statement. The placeholders in this example are filled up with the values that were passed to the SQL extension method. Whenever possible, instead of writing the provided values to the sql statement, Telerik OpenAccess ORM uses binding variables.
Oracle
With Oracle as your backend, it is basically the same as with MS SQL Server, just the statement is a bit different.
This could be executed with the following LINQ query.
See the Oracle Fulltext link below, for more details on how to use the full text features of Oracle.
MySql
For MySql the statement to execute a full text query looks like the following statement.
For this statement we need to create a LINQ query that looks like this.
In this case we are using the example provided by the MySql documentation. See the links below for more details. We pass 3 parameters to the SQL extension method based on the full text definition of the table.
PostgreSql
For PostgreSql we need to execute a query like the following:
Again here we have a LINQ query:
CONCLUSION
The SQL extension method is not limited to make use of only the full text features of the various database backend, but will give you also the possibility to execute other unmapped functions.
REFERENCES