Mercurial > pub > bltoolkit
comparison HowTo/DataAccess/AbstractAccessor.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 using System.Collections.Generic; | |
| 3 | |
| 4 using NUnit.Framework; | |
| 5 | |
| 6 using BLToolkit.Data; | |
| 7 using BLToolkit.DataAccess; | |
| 8 | |
| 9 namespace HowTo.DataAccess | |
| 10 { | |
| 11 [TestFixture] | |
| 12 public class AbstractAccessor | |
| 13 { | |
| 14 public /*[a]*/abstract/*[/a]*/ class /*[a]*/PersonAccessor : DataAccessor<Person>/*[/a]*/ | |
| 15 { | |
| 16 public /*[a]*/abstract/*[/a]*/ Person /*[a]*/SelectByName/*[/a]*/(Person person); | |
| 17 public /*[a]*/abstract/*[/a]*/ Person /*[a]*/SelectByName/*[/a]*/(string firstName, string lastName); | |
| 18 | |
| 19 public /*[a]*/abstract/*[/a]*/ int /*[a]*/Insert/*[/a]*/ (Person person); | |
| 20 | |
| 21 [/*[a]*/SqlQuery(/*[/a]*/"SELECT Top /*[a]*/{0}/*[/a]*/ * FROM Person ORDER BY PersonID"/*[a]*/)]/*[/a]*/ | |
| 22 [/*[a]*/Index("ID")/*[/a]*/] | |
| 23 public /*[a]*/abstract/*[/a]*/ Dictionary<int,Person> /*[a]*/SelectTop/*[/a]*/([/*[a]*/Format(0)/*[/a]*/] int top); | |
| 24 | |
| 25 private SprocQuery<Person> _query; | |
| 26 public SprocQuery<Person> Query | |
| 27 { | |
| 28 get | |
| 29 { | |
| 30 if (_query == null) | |
| 31 _query = new SprocQuery<Person>(DbManager); | |
| 32 return _query; | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 [Test] | |
| 38 public void Test() | |
| 39 { | |
| 40 using (DbManager db = new DbManager()) | |
| 41 { | |
| 42 PersonAccessor pa = /*[a]*/DataAccessor.CreateInstance<PersonAccessor>(db)/*[/a]*/; | |
| 43 | |
| 44 pa.BeginTransaction(); | |
| 45 | |
| 46 // Insert and get id. | |
| 47 // | |
| 48 Person person = new Person(); | |
| 49 | |
| 50 person.FirstName = "Crazy"; | |
| 51 person.LastName = "Frog"; | |
| 52 person.Gender = Gender.Unknown; | |
| 53 | |
| 54 int id = pa./*[a]*/Insert(person)/*[/a]*/; | |
| 55 | |
| 56 // SelectByName. | |
| 57 // | |
| 58 person = pa./*[a]*/SelectByName("Crazy", "Frog")/*[/a]*/; | |
| 59 | |
| 60 Assert.IsNotNull(person); | |
| 61 | |
| 62 // Select top. | |
| 63 // | |
| 64 Dictionary<int,Person> dic = pa./*[a]*/SelectTop(10)/*[/a]*/; | |
| 65 | |
| 66 Assert.IsTrue(dic.Count <= 10); | |
| 67 | |
| 68 // Delete. | |
| 69 // | |
| 70 pa.Query.Delete(person); | |
| 71 | |
| 72 pa.CommitTransaction(); | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 |
