-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
145 lines (107 loc) · 5.14 KB
/
Copy pathProgram.cs
File metadata and controls
145 lines (107 loc) · 5.14 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Insight.Database;
using ODAC_Sample_FluentDAO;
using ODAC_Sample_InsightDatabase;
using ODAC_Sample_NHibernate;
//using Oracle.ManagedDataAccess.Client;
//using Oracle.ManagedDataAccess.Types;
using ODAC_Sample_NHibernate.Entities.Hr;
using ODACSample.EF;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
namespace ODAC_Sample
{
class Program
{
static void Main(string[] args)
{
NHibernate_Example();
//ADO_NET_Example();
//EntityFramework_Example();
//FluentDAO_Example();
//InsightDatabase_Example();
Console.WriteLine();
Console.WriteLine("Press 'Enter' to continue");
Console.ReadLine();
}
/// <summary>
/// <see cref="https://github.com/jonwagner/Insight.Database"/>
/// </summary>
static void InsightDatabase_Example()
{
InsightDbProvider.RegisterSqlProvider();
var conn = new SqlConnection(@"Data Source=www.machinejar.com\DEVSQL02;Initial Catalog=AdventureWorks2014;Persist Security Info=True;User ID=db_user;Password=db_password");
var productAddresses = conn.QuerySql<dynamic>("select top 10 * from Person.Address");
Console.WriteLine(productAddresses.First().AddressLine1);
Console.ReadLine();
}
/// <summary>
/// <see cref="https://github.com/leadnt/FluentDAO"/>
/// </summary>
static void FluentDAO_Example()
{
var context = DbContextConfiguration.GetContextUsing(@"Data Source=www.machinejar.com\DEVSQL02;Initial Catalog=AdventureWorks2014;Persist Security Info=True;User ID=db_user;Password=db_password");
List<dynamic> productAddresses = context.Sql("select top 10 * from Person.Address").QueryMany<dynamic>();
Console.WriteLine(productAddresses.First().AddressLine1);
Console.ReadLine();
}
static void EntityFramework_Example()
{
var context = new OracleDbContext();
var results = context.Products.Where(p => p.Category.CategoryName == "Beverages");
foreach (var result in results)
{
Console.WriteLine("Product Name: {0} | Quantity Per Unit: {1}, | Unit Price: {2}", result.ProductName, result.QuantityPerUnit, result.UnitPrice);
}
}
static void NHibernate_Example()
{
var cs = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=www.machinejar.com)(PORT=1523)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=devorc02)));User Id=hr;Password=hr;";
var nhconfig = NHibernateConfig.Instance(cs);
if (nhconfig.SessionFactory == null)
Console.WriteLine("Oracle/NHibernate initialization failed.");
else
Console.WriteLine("Oracle/NHibernate initialization passed!.");
Console.ReadLine();
var session = nhconfig.SessionFactory.OpenSession();
//var query = session.CreateSQLQuery("CALL HR_DEPTPERCOUNTRY (:RS_CURSOR, :CNTR_CD)");
var query = session.GetNamedQuery("HR_DEPTPERCOUNTRY");
query.SetString("CNTR_CD", "UK");
//query.AddEntity(typeof(HumanResourcesInfo));
//query.SetResultTransformer(Transformers.AliasToBean<HumanResourcesInfo>());
var results = query.List<HumanResourcesInfo>();
foreach (var result in results)
{
Console.WriteLine("Dept Name: {0} | Address: {1}, | Country: {2}", result.Department, result.Address, result.Country);
}
}
static void ADO_NET_Example()
{
var cs = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=www.machinejar.com)(PORT=1522)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=devorc02)));User Id=hr;Password=hr;";
OracleConnection con = new OracleConnection();
con.ConnectionString = cs;
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "HR_DEPTPERCOUNTRY";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
OracleParameter orcOutParam = new OracleParameter("RS_CURSOR", OracleDbType.RefCursor);
orcOutParam.Size = 50;
orcOutParam.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(orcOutParam);
OracleParameter orcParam = new OracleParameter("CNTR_CD", OracleDbType.Varchar2);
orcParam.Size = 50;
orcParam.Value = "UK";
orcParam.Direction = System.Data.ParameterDirection.Input;
cmd.Parameters.Add(orcParam);
cmd.ExecuteNonQuery();
OracleDataReader reader = ((OracleRefCursor)cmd.Parameters["RS_CURSOR"].Value).GetDataReader();
while (reader.Read())
{
Console.WriteLine("Dept Name: {0} | Address: {1}, | Country: {2}", reader.GetString(0), reader.GetString(1), reader.GetString(2));
}
}
}
}