0
|
1 using System;
|
|
2 using System.Linq;
|
|
3
|
|
4 using BLToolkit.Data.DataProvider;
|
|
5 using BLToolkit.Data.Linq;
|
|
6
|
|
7 using NUnit.Framework;
|
|
8
|
|
9 namespace Data.Linq
|
|
10 {
|
|
11 using Model;
|
|
12
|
|
13 [TestFixture]
|
|
14 public class DataContextTest
|
|
15 {
|
|
16 [Test]
|
|
17 public void TestContext()
|
|
18 {
|
|
19 var ctx = new DataContext(ProviderName.Access);
|
|
20
|
|
21 ctx.GetTable<Person>().ToList();
|
|
22
|
|
23 ctx.KeepConnectionAlive = true;
|
|
24
|
|
25 ctx.GetTable<Person>().ToList();
|
|
26 ctx.GetTable<Person>().ToList();
|
|
27
|
|
28 ctx.KeepConnectionAlive = false;
|
|
29
|
|
30 using (var tran = new DataContextTransaction(ctx))
|
|
31 {
|
|
32 ctx.GetTable<Person>().ToList();
|
|
33
|
|
34 tran.BeginTransaction();
|
|
35
|
|
36 ctx.GetTable<Person>().ToList();
|
|
37 ctx.GetTable<Person>().ToList();
|
|
38
|
|
39 tran.CommitTransaction();
|
|
40 }
|
|
41 }
|
|
42
|
|
43 [Test]
|
|
44 public void TestContextToString()
|
|
45 {
|
|
46 using (var ctx = new DataContext(ProviderName.Access))
|
|
47 {
|
|
48 Console.WriteLine(ctx.GetTable<Person>().ToString());
|
|
49
|
|
50 var q =
|
|
51 from s in ctx.GetTable<Person>()
|
|
52 select s.FirstName;
|
|
53
|
|
54 Console.WriteLine(q.ToString());
|
|
55 }
|
|
56 }
|
|
57 }
|
|
58 }
|