Search   

Sunday, February 05, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  Composing Queri...
 Composing Queries in NDO
 
 5/15/2006 5:30:25 PM
anonymous
20 posts


Composing Queries in NDO
Hi, I'm porting an application with SQL code to NDO. My application has a form in which a user can input one, two or more fields for filtering a query. As soon as the search is started, I want to walk through all controls of the form and create the Where clause dynamically during runtime. Depending on the search criteria the SQL statement can include joins among several tables. Can I do something like that in NDO too? C.R.
 5/15/2006 5:42:06 PM
Mirko
109 posts
5th


Re: Composing Queries in NDO
Hi, you can either create a NDO query (this is prefereable for most cases) or you submit a SQL pass-through query. But this brings database dependencies into your application which is normally to be avoided. The SQL query has to return a result set with all columns being defined in the mapping file for the result class. Here is an example: NDOql Query: string query = string.Emtpy; Order.QueryHelper qh = new Order.QueryHelper(); if (includeOrderNumber) query += qh.OrderNumber + Query.Op.Eq + txtOrderNumber.Text + Query.Op.And; if (includeType) query += qh.type + Query.Op.Like + txtType.Text + Query.Op.And; .... and so on // Now remove the redundant AND query = query.Substring(0, query.Length - Query.Op.And.Length); Query q = pm.newQuery(typeof(Order), query, false); IList aufträge = q.Execute(); Sql Query: string query = "SELECT OrderNumber, Typ, ... FROM Orders WHERE "; // Take care of all columns in SELECT that are needed to create an object of type order if (includeOrderNumber) query += "OrderNumber" + Query.Op.Eq + txtOrderNumber.Text + Query.Op.And; if (includeTyp) query += "Typ" + Query.Op.Like + txtTyp.Text + Query.Op.And; .... und so weiter // Now remove the redundant AND query = query.Substring(0, query.Length - Query.Op.And.Length); Query q = pm.newQuery(typeof(Order), query, false, Query.Languge.Sql); IList aufträge = q.Execute(); Hope that helps! Mirko Matytschak
  NDO-Forum postings in english please, if possible.  Developing with NDO  Composing Queri...
  SearchSearch  Forum HomeForum Home