TableName

BLToolkit.NET

Business Logic Toolkit for .NET www.bltoolkit.net
 

The TableName attribute specifies a name of the table represented by the decorated object.

TableName.cs
using System;

using NUnit.Framework;

using BLToolkit.DataAccess;
using BLToolkit.Mapping;

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

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

        [Test]
        public void Test1()
        {
            SqlQuery<MyPersonObject> query = new SqlQuery<MyPersonObject>();

            MyPersonObject person = query.SelectByKey(1);

            Assert.IsNotNull(person);
        }

        [Test]
        public void Test2()
        {
            SprocQuery<MyPersonObject> query = new SprocQuery<MyPersonObject>();

            MyPersonObject person = query.SelectByKey(1);

            Assert.IsNotNull(person);
        }
    }
}
DataAccessor.SelectByKeySql and DataAccessor.SelectByKey methods generate and execute the following SQL statement:
-- SelectByKeySql
SELECT
    [MiddleName],
    [PersonID],
    [LastName],
    [FirstName]
FROM
    [Person]
WHERE
    [PersonID] = @PersonID

-- SelectByKey
exec Person_SelectByKey @id=1
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add
            key   = "ConnectionString"
            value = "Server=.;Database=BLToolkitData;Integrated Security=SSPI"/>
    </appSettings>
</configuration>
Create.sql script
 
© 2010 www.bltoolkit.net
[email protected]