Mercurial > pub > bltoolkit
comparison HowTo/DataAccess/ExecuteObject.cs @ 0:f990fcb411a9
Копия текущей версии из github
| author | cin |
|---|---|
| date | Thu, 27 Mar 2014 21:46:09 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f990fcb411a9 |
|---|---|
| 1 using System; | |
| 2 | |
| 3 using NUnit.Framework; | |
| 4 | |
| 5 using BLToolkit.DataAccess; | |
| 6 | |
| 7 namespace HowTo.DataAccess | |
| 8 { | |
| 9 [TestFixture] | |
| 10 public class ExecuteObject | |
| 11 { | |
| 12 public abstract class /*[a]*/PersonAccessor/*[/a]*/ : /*[a]*/DataAccessor/*[/a]*/<Person> | |
| 13 { | |
| 14 // Here we explicitly specify a stored procedure name. | |
| 15 // | |
| 16 [SprocName("Person_SelectByKey")] | |
| 17 public abstract /*[a]*/Person/*[/a]*/ GetByID(int @id); | |
| 18 | |
| 19 // SQL query text. | |
| 20 // | |
| 21 [SqlQuery("SELECT * FROM Person WHERE PersonID = @id")] | |
| 22 public abstract /*[a]*/Person/*[/a]*/ GetPersonByID(int @id); | |
| 23 | |
| 24 // Specify action name. | |
| 25 // Stored procedure name is generated based on convention | |
| 26 // defined by DataAccessor.GetDefaultSpName method. | |
| 27 // | |
| 28 [ActionName("SelectByName")] | |
| 29 public abstract /*[a]*/Person/*[/a]*/ GetPersonByName(string @firstName, string @lastName); | |
| 30 | |
| 31 // By default method name defines an action name | |
| 32 // which is converted to a stored procedure name. | |
| 33 // Default conversion rule is ObjectName_MethodName. | |
| 34 // This method calls the Person_SelectByName stored procedure. | |
| 35 // | |
| 36 public abstract /*[a]*/Person/*[/a]*/ SelectByName(string @firstName, string @lastName); | |
| 37 } | |
| 38 | |
| 39 [Test] | |
| 40 public void Test() | |
| 41 { | |
| 42 PersonAccessor pa = DataAccessor.CreateInstance<PersonAccessor>(); | |
| 43 | |
| 44 // ExecuteObject. | |
| 45 // | |
| 46 Assert.IsNotNull(pa.GetByID (1)); | |
| 47 Assert.IsNotNull(pa.GetPersonByID (2)); | |
| 48 Assert.IsNotNull(pa.GetPersonByName("Tester", "Testerson")); | |
| 49 Assert.IsNotNull(pa.SelectByName ("Tester", "Testerson")); | |
| 50 } | |
| 51 } | |
| 52 } |
