-
Notifications
You must be signed in to change notification settings - Fork 113
DataAccess.TableName
Igor Tkachev edited this page May 22, 2016
·
1 revision
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>
<connectionStrings>
<add
name = "DemoConnection"
connectionString = "Server=.;Database=BLToolkitData;Integrated Security=SSPI"
providerName = "System.Data.SqlClient" />
</connectionStrings>
</configuration>