-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUsageExample.txt
31 lines (24 loc) · 1.13 KB
/
UsageExample.txt
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
// An example class instance
Order classInstance = Order.Create();
// DataTable from class
DataTable dataTable = Table.FromClass<Order>();
string createTableFromTable = SQLScript.CreateTable(dataTable);
// - or -
string insertIntoFromClass = SQLScript.InsertInto(classInstance);
// Populate a List<> of class from a DataTable
IList<Order> orderList = Table.ToClassInstanceCollection<Order>(tableWithManyRecords);
// You can either write out the SQL script to a file...
File.WriteAllText("create_table.sql",insertIntoFromClass);
// Or use it directly in
DatabaseQuery.NonQueryCommand(ConnectionString, insertIntoFromClass);
// DataTable from SQL query
DataTable queryTable = DatabaseQuery.ToDataTable(ConnectionString, "SELECT TOP 1 * FROM [{0}]", TableName);
// Check that our DataTable is good
if (!Helper.IsValidDatatable(dataTable))
return;
if (!Helper.IsValidDatatable(queryTable))
return;
// Emit a dynamic assembly where the class's public properties' names match the DataTable's ColumnNames
Type datatableAssembly = Table.ToAssembly(dataTable);
// Generate the C# class as C# code
FileInfo csCodeFile = Table.ToCSharpCode(queryTable);