-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDatabaseQuery_ExecuteReader.linq
73 lines (63 loc) · 1.98 KB
/
DatabaseQuery_ExecuteReader.linq
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
<Query Kind="Program">
<Connection>
<ID>5b1167bd-8927-424f-8aab-b93bd7b5b1fd</ID>
<Persist>true</Persist>
<Server>devsqlag</Server>
<Database>DevExtendHealth</Database>
<NoCapitalization>true</NoCapitalization>
<IncludeSystemObjects>true</IncludeSystemObjects>
</Connection>
<Namespace>analyticsLibrary.dbObjects</Namespace>
<Namespace>analyticsLibrary.library</Namespace>
</Query>
void Main()
{
var sql = @"
SELECT TOP 1000
Person.personId,
Person.firstName,
Person.lastName,
Person.loginInformationUserName,
a.hraAdministratorName
FROM dbo.Person
INNER JOIN
(
SELECT
personId,
fundingSourceId
FROM Hra.V_ActiveAllocationSchedule
GROUP BY personId, fundingSourceId
HAVING COUNT(*) > 1
) AS CustomerWithMultipleAllocationSchedules
ON CustomerWithMultipleAllocationSchedules.personId = Person.personId
JOIN Reimbursement.PartnerPerson pp ON CustomerWithMultipleAllocationSchedules.personId = pp.personId
JOIN Reimbursement.CampaignSegmentHra cs on cs.campaignSegmentId = pp.campaignSegmentId
JOIN Reimbursement.HraAdministrator a on cs.hraAdministratorId = a.hraAdministratorId
WHERE Person.loginInformationUserName IS NOT NULL
";
var command = Connection.CreateCommand();
command.CommandText = sql;
Connection.Open();
var reader = command.ExecuteReader();
var data = new List<logon>();
while (reader.Read())
{
data.Add(new logon()
{
personId = reader.GetInt32(0),
firstName = reader.GetString(1),
lastName = reader.GetString(2),
hraAdministratorName = reader.GetString(3),
});
}
if(Connection.State == ConnectionState.Open) Connection.Close();
data.Dump();
}
public class logon
{
public int personId { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string loginInformationUserName { get; set; }
public string hraAdministratorName { get; set; }
}