This project is read-only.

Query parameters

In NSQLObjects, there are two ways to filter queries. You can define parameters to queries and use them to restrict returned rows with normal SQL filters like where. You can also add filters to existing queries that will further restrict returned rows.
Query parameters
You can define query parameters after query name. Syntax for parameters is:
“query” name [ “(“ param_name “:” type { “,” param_name “:” type } ] ...

For example, a query that will retrieve all products ordered by a customer might look like:
default {
  type money: decimal;
  type smallint: int;
query CustomerProducts(CID:int) [[
SELECT  Customers.CustomerID, Customers.CompanyName, 
  Orders.OrderDate, [Order Details].Quantity,
  [Order Details].UnitPrice AS LineUnitPrice, 
  Products.ProductID, Products.ProductName, 
  Products.UnitPrice, Products.Discontinued
FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID 
  INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID 
  INNER JOIN Products ON [Order Details].ProductID = Products.ProductID
WHERE Customers.CustomerID = @CID
]] ;

You must assign value to CID before you load query.
 using (var ctx = SqlDataContext.CreateContext()) {
    CustomerProducts cu = new CustomerProducts () { CID  = <actual id> };

Query filters

Last edited Oct 26, 2010 at 10:03 AM by nolics, version 3


No comments yet.