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 ActionSprocName attribute is applied to a business object (NOT to data accessor class) and associates ActionName with stored procedure name.

ActionSprocName.cs

using System;
using NUnit.Framework;
using BLToolkit.DataAccess;

namespace HowTo.DataAccess { [TestFixture] public class ActionSprocName { [ActionSprocName("GetByName", "Person_SelectByName")] public class Person { public int PersonID; public string LastName; public string FirstName; public string MiddleName; }

public abstract class PersonAccessor : DataAccessor { // Default action name is 'SelectByKey'. // Stored procedure name is 'Person_SelectByKey'. // public abstract Person SelectByKey(int @id);

// Default action name is 'GetByName'. // Stored procedure name is 'Person_SelectByName' // defined by the ActionSprocName attribute of the Person class. // public abstract Person GetByName(string @firstName, string @lastName); }

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

Person person1 = pa.SelectByKey(1);

Assert.IsNotNull(person1);

Person person2 = pa.GetByName(person1.FirstName, person1.LastName);

Assert.AreEqual(person1.PersonID, person2.PersonID); } } }

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