This repository was archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (69 loc) · 3.35 KB
/
Program.cs
File metadata and controls
82 lines (69 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
using POCOGenerator;
using POCOGenerator.Objects;
namespace SelectingObjectsDemo
{
class Program
{
static void Main()
{
IGenerator generator = GeneratorFactory.GetGenerator();
try { generator.Settings.Connection.ConnectionString = File.ReadAllText("ConnectionString.txt"); } catch { }
if (string.IsNullOrEmpty(generator.Settings.Connection.ConnectionString))
generator.Settings.Connection.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=AdventureWorks2014;Integrated Security=True";
// database object is selected when:
// 1. explicitly included: Settings.IncludeAll, Settings.Tables.IncludeAll, Settings.Tables.Include.Add(), ...
// 2. not explicitly excluded. it doesn't appear in any excluding setting: Settings.Tables.ExcludeAll, Settings.Tables.Exclude.Add(), ...
// select all the tables under HumanResources & Purchasing schemas
// and select table Production.Product
generator.Settings.DatabaseObjects.Tables.Include.Add("HumanResources.*");
generator.Settings.DatabaseObjects.Tables.Include.Add("Purchasing.*");
generator.Settings.DatabaseObjects.Tables.Include.Add("Production.Product");
// select all views except views under Production & Sales schemas
// and except view Person.vAdditionalContactInfo
generator.Settings.DatabaseObjects.Views.IncludeAll = true;
generator.Settings.DatabaseObjects.Views.Exclude.Add("Production.*");
generator.Settings.DatabaseObjects.Views.Exclude.Add("Sales.*");
generator.Settings.DatabaseObjects.Views.Exclude.Add("Person.vAdditionalContactInfo");
generator.ServerBuilt += (object sender, ServerBuiltEventArgs e) =>
{
foreach (Database database in e.Server.Databases)
{
Console.WriteLine("Tables:");
Console.WriteLine("-------");
foreach (Table table in database.Tables)
Console.WriteLine(table);
Console.WriteLine();
Console.WriteLine("Views:");
Console.WriteLine("------");
foreach (View view in database.Views)
Console.WriteLine(view);
Console.WriteLine();
}
// do not generate classes
e.Stop = true;
};
GeneratorResults results = generator.Generate();
PrintError(results, generator.Error);
Console.WriteLine();
Console.WriteLine("Press any key to continue . . .");
Console.ReadKey(true);
}
private static void PrintError(GeneratorResults results, Exception Error)
{
bool isError = (results & GeneratorResults.Error) == GeneratorResults.Error;
if (isError)
{
Console.WriteLine();
Console.WriteLine("Error Result: {0}", results);
}
if (Error != null)
{
Console.WriteLine("Error: {0}", Error.Message);
Console.WriteLine("Error Stack Trace:");
Console.WriteLine(Error.StackTrace);
}
}
}
}