public NormalizedStatementStatistics GetByUniqueKey(NormalizedStatementStatisticsUniqueKey key) { using (var context = CreateContextFunc()) { return(context.NormalizedStatementStatistics.Where(x => x.ApplicationName == key.ApplicationName && x.DatabaseID == key.DatabaseID && x.Date == key.Date && x.NormalizedStatementID == key.NormalizedStatementID && x.UserName == key.UserName).SingleOrDefault()); } }
private void PersistStatementStatistics(NormalizedStatementStatistics newStatistics) { var repository = repositories.GetNormalizedStatementStatisticsRepository(); var uniqueKey = new NormalizedStatementStatisticsUniqueKey() { ApplicationName = newStatistics.ApplicationName, DatabaseID = newStatistics.DatabaseID, Date = newStatistics.Date, NormalizedStatementID = newStatistics.NormalizedStatementID, UserName = newStatistics.UserName }; var oldStatistics = repository.GetByUniqueKey(uniqueKey); if (oldStatistics == null) { repository.Create(newStatistics); } else { NormalizedStatementStatisticsMergeUtility.ApplySample(oldStatistics, newStatistics); repository.Update(oldStatistics); } }