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


Search the wiki


using System;
using System.Collections;
using System.Collections.Generic;

using NUnit.Framework;

using BLToolkit.DataAccess;

namespace HowTo.DataAccess { [TestFixture] public class ExecuteList { public abstract class PersonAccessor : DataAccessor { // This method reads a list of Person objects. // [ActionName("SelectAll")] public abstract List<Person> GetPersonList1();

// Here we help the method to get object type information. // ObjectTypeAttribute can be applied to the class itself. // In this case there is no need to specify object type for each method. // Another way to specify object type is a generic parameter // of the DataAccessor<T> class. // [SqlQuery("SELECT * FROM Person")] [ObjectType(typeof(Person))] public abstract ArrayList GetPersonList2();

// This method reads a list of scalar values. // [SqlQuery("SELECT PersonID FROM Person")] public abstract List<int> GetPersonIDList(); }

[Test] public void Test() { PersonAccessor pa = DataAccessor.CreateInstance<PersonAccessor>();

// ExecuteList. // IList list; list = pa.GetPersonList1(); list = pa.GetPersonList2();

foreach (Person p in list) Console.WriteLine("{0}: {1} {2}", p.ID, p.FirstName, p.LastName);

// ExecuteScalarList. // List<int> slist = pa.GetPersonIDList();

foreach (int id in slist) Console.WriteLine("{0}", id); } } }


using System;

using BLToolkit.DataAccess; using BLToolkit.Mapping;

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

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


using System;

using BLToolkit.Mapping;

namespace HowTo.DataAccess { public enum Gender { [MapValue("F")] Female, [MapValue("M")] Male, [MapValue("U")] Unknown, [MapValue("O")] Other } }


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

© 2010