Created
April 25, 2016 11:42
-
-
Save margusmartsepp/a138ce068efb6ec2b1cb4a49a8cf05a8 to your computer and use it in GitHub Desktop.
dapper example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static SqlConnection GetDatabaseConnection() | |
{ | |
var connectionString = ConfigurationManager.ConnectionStrings["exampleEntities"].ConnectionString; | |
var csBuilder = new EntityConnectionStringBuilder(connectionString); | |
var connection = new SqlConnection(csBuilder.ProviderConnectionString); | |
return connection; | |
} | |
public static void Analyze() | |
{ | |
using (var connection = GetDatabaseConnection()) | |
{ | |
var players = connection.Query<Player>($@"Select * from players"); | |
foreach (var player in players) | |
{ | |
var lastEntryLogs = connection.Query<ErrorAlarmsModel>($@" | |
SELECT TOP 1 | |
[id] as Id, | |
[pleierid] as PlayerId, | |
[pleiername] as PlayerName, | |
[alarmtxt] as AlarmTxt, | |
[lastsent] as LastSent, | |
[alarmstart] as AlarmStart, | |
[alarmstop] as AlarmStop, | |
[acknowledge] as Acknowledgement, | |
[acknowledgedate] as AcknowledgementDate, | |
[alarmlevel] as AlarmLevel | |
FROM alarms | |
Where pleierid = {player.ID} | |
ORDER BY AlarmStop DESC") | |
.FirstOrDefault(); | |
if (lastEntryLogs == null) | |
continue; | |
Console.WriteLine($"{lastEntryLogs.Id} {lastEntryLogs.PlayerId}"); | |
} | |
} | |
} | |
public class ErrorAlarmsModel | |
{ | |
public int Id { get; set; } | |
public int PlayerId { get; set; } | |
public string PlayerName { get; set; } | |
public string AlarmTxt { get; set; } | |
public DateTime LastSent { get; set; } | |
public DateTime AlarmStart { get; set; } | |
public DateTime AlarmStop { get; set; } | |
public string Acknowledgment { get; set; } | |
public DateTime AcknowledgmentDate { get; set; } | |
public string AlarmLevel { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment