Use a query

First you must set up a database connection. The connection defined in a .dbmodel file is only used during compilation. In an ASP.net application, you normally set the connection in the global.asax file.

To set a default connection, use:
NSQLObjects.Persistence.SqlDataContext.SetDefaultConnection(…);

For all NSQLObjects database operations we must create a data context. It is recommended that the data context is always encapsulated within a using statement.

To load previously defined CustomerNames query use:
using (var ctx = SqlDataContext.CreateContext()) {
    var customerNames = ctx.LoadQuery<CustomerNames>();
    foreach(var x in customerNames)
      …
}

Normally loaded query is an IList object which you can manipulate. For example you can iterate through all items of a query with the foreach statement.

There are several ways to filter, sort and page queries. See Sorting, paging and filtering queries

Update data

Last edited Oct 26, 2010 at 9:48 AM by nolics, version 4

Comments

No comments yet.