SQL Queries

There might be situations where the described mechanisms are not sufficient. In such cases you can use ordinary SQL strings to fetch objects. These are called SQL pass-through queries. But the syntax is not checked and the column names are not mapped in that case. So if the name of a database column has changed, it is not sufficient to change the name in the mapping file. All SQL pass-through queries that use that column have to be changed, too.

This is how you create a SQL pass-through query:

Query q = pm.NewQuery(typeof(Travel), "SELECT * FROM Employee WHERE Purpose LIKE 'TechEd 2006'", true, Query.Language.SQL);

Important: The query strings must begin with SELECT *. NDO replaces the ‘*’ with the fields that belong to the respective result type (in the case of hollow queries, this is only the Id column). The rest of the query string is not changed by NDO.