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 application, you normally set the connection in the global.asax file.

To set a default connection, use:

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 8:48 AM by nolics, version 4


No comments yet.