-
Notifications
You must be signed in to change notification settings - Fork 113
DataAccess.ScalarFieldName
Igor Tkachev edited this page May 22, 2016
·
1 revision
If your method returns a dictionary of scalar values, you will have to specify the name or index of the field used to populate the scalar list. The ScalarFieldName attribute allows you to do that.
ScalarFieldName.cs
using System;
using System.Collections.Generic;
using NUnit.Framework;
using BLToolkit.DataAccess;
namespace HowTo.DataAccess
{
[TestFixture]
public class ScalarFieldName
{
public abstract class TestAccessor : DataAccessor
{
[SqlQuery("SELECT PersonID, FirstName FROM Person")]
[Index("PersonID")]
[ScalarFieldName("FirstName")]
public abstract Dictionary<int, string> GetPersonNameDictionary();
}
[Test]
public void Test()
{
TestAccessor pa = DataAccessor.CreateInstance<TestAccessor>();
IDictionary<int, string> dic = pa.GetPersonNameDictionary();
Assert.AreEqual("John", dic[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>