Business Logic Toolkit for .NET
www.bltoolkit.net
Welcome Guest, you are in: Login
|  Home   |  Download   |  Documentation   |  Discussions   |  Issues   |  License   |
RSS RSS

Navigation




Search the wiki
»

PoweredBy
The SqlQuery and SprocQuery classes can be used to perform simple CRUDL operations such as SelectByKey, SelectAll, Insert, Update, and Delete.

OpenConfigQuery.cs

using System;

using NUnit.Framework;

using BLToolkit.Data; using BLToolkit.DataAccess; using BLToolkit.Mapping;

namespace HowTo.DataAccess { [TestFixture] public class OpenConfigQuery { public class Person { [MapField("PersonID"), PrimaryKey, NonUpdatable] public int ID;

public string LastName; public string FirstName; public string MiddleName; }

// DbManager is created by SqlQuery. // [Test] public void Test1() { SqlQuery<Person> query = new SqlQuery<Person>();

Person person = query.SelectByKey(1);

Assert.IsNotNull(person); }

// SqlQuery takes DbManager as a parameter. // [Test] public void Test2() { using (DbManager db = new DbManager()) { SqlQuery<Person> query = new SqlQuery<Person>(db);

Person person = query.SelectByKey(1);

Assert.IsNotNull(person); } }

// SqlQuery method takes DbManager as a parameter. // [Test] public void Test3() { using (DbManager db = new DbManager()) { SqlQuery<Person> query = new SqlQuery<Person>();

Person person = query.SelectByKey(db, 1);

Assert.IsNotNull(person); } } } }

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <add
            name             = "DemoConnection"
            connectionString = "Server=.;Database=BLToolkitData;Integrated Security=SSPI"
            providerName     = "System.Data.SqlClient" />
    </connectionStrings>
</configuration>

CreateSql
© 2010 www.bltoolkit.net