comparison UnitTests/Linq/TestDbManager.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.Linq;
3 using System.Linq.Expressions;
4 using System.Reflection;
5 using System.Text;
6
7 using BLToolkit.Data;
8 using BLToolkit.Data.DataProvider;
9 using BLToolkit.Data.Linq;
10 using BLToolkit.Data.Sql;
11
12 namespace Data.Linq
13 {
14 using Model;
15
16 public class TestDbManager : DbManager, ITestDataContext
17 {
18 public TestDbManager(string configString)
19 : base(configString)
20 {
21 }
22
23 public TestDbManager()
24 : base(ProviderName.Access)
25 {
26 }
27
28 public Table<Person> Person { get { return GetTable<Person>(); } }
29 public Table<Patient> Patient { get { return GetTable<Patient>(); } }
30 public Table<Doctor> Doctor { get { return GetTable<Doctor>(); } }
31 public Table<Parent> Parent { get { return GetTable<Parent>(); } }
32 public Table<Parent1> Parent1 { get { return GetTable<Parent1>(); } }
33 public Table<IParent> Parent2 { get { return GetTable<IParent>(); } }
34 public Table<Parent4> Parent4 { get { return GetTable<Parent4>(); } }
35 public Table<Parent5> Parent5 { get { return GetTable<Parent5>(); } }
36 public Table<ParentInheritanceBase> ParentInheritance { get { return GetTable<ParentInheritanceBase>(); } }
37 public Table<ParentInheritanceBase2> ParentInheritance2 { get { return GetTable<ParentInheritanceBase2>(); } }
38 public Table<ParentInheritanceBase3> ParentInheritance3 { get { return GetTable<ParentInheritanceBase3>(); } }
39 public Table<ParentInheritanceBase4> ParentInheritance4 { get { return GetTable<ParentInheritanceBase4>(); } }
40 public Table<ParentInheritance1> ParentInheritance1 { get { return GetTable<ParentInheritance1>(); } }
41 public Table<ParentInheritanceValue> ParentInheritanceValue { get { return GetTable<ParentInheritanceValue>(); } }
42 public Table<Child> Child { get { return GetTable<Child>(); } }
43 public Table<GrandChild> GrandChild { get { return GetTable<GrandChild>(); } }
44 public Table<GrandChild1> GrandChild1 { get { return GetTable<GrandChild1>(); } }
45 public Table<LinqDataTypes> Types { get { return GetTable<LinqDataTypes>(); } }
46 public Table<LinqDataTypes2> Types2 { get { return GetTable<LinqDataTypes2>(); } }
47 public Table<TestIdentity> TestIdentity { get { return GetTable<TestIdentity>(); } }
48
49 [TableFunction(Name="GetParentByID")]
50 public Table<Parent> GetParentByID(int? id)
51 {
52 return GetTable<Parent>(this, (MethodInfo)MethodBase.GetCurrentMethod(), id);
53 }
54
55 public string GetSqlText(SqlQuery sql)
56 {
57 var provider = ((IDataContext)this).CreateSqlProvider();
58
59 //provider.SqlQuery = sql;
60
61 sql = provider.Finalize(sql);
62
63 var cc = provider.CommandCount(sql);
64 var sb = new StringBuilder();
65
66 var commands = new string[cc];
67
68 for (var i = 0; i < cc; i++)
69 {
70 sb.Length = 0;
71
72 provider.BuildSql(i, sql, sb, 0, 0, false);
73 commands[i] = sb.ToString();
74 }
75
76 return string.Join("\n\n", commands);
77 }
78
79 #if !MONO
80 [MethodExpression("Expression9")]
81 static public IQueryable<Parent> GetParent9(ITestDataContext db, Child ch)
82 {
83 throw new InvalidOperationException();
84 }
85
86 [MethodExpression("Expression9")]
87 public IQueryable<Parent> GetParent10(Child ch)
88 {
89 throw new InvalidOperationException();
90 }
91
92 static Expression<Func<ITestDataContext,Child,IQueryable<Parent>>> Expression9()
93 {
94 return (db,ch) =>
95 from p in db.Parent
96 where p.ParentID == (int)Math.Floor(ch.ChildID / 10.0)
97 select p;
98 }
99 #endif
100 }
101 }