Skip to content

Instantly share code, notes, and snippets.

View Alexei000's full-sized avatar

Alex Dragan Alexei000

View GitHub Profile
@Alexei000
Alexei000 / direct_fetch.cs
Created September 5, 2017 14:26
Medium article - direct fetch with eager loading
var envIds = new List<int> {5};
DateTime fromDate = DateTime.Now.AddDays(-7).Date;
DateTime toDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
var results = DataAccess.ImportingSystemTestResultRepository.All
.Include(tr => tr.ImportingSystemTestRunTime)
.Include(tr => tr.ImportingSystemTestQueue)
.Include(tr => tr.ImportingSystemTest)
.Include(tr => tr.ImportingSystem)
.Include(tr => tr.Environment)
@Alexei000
Alexei000 / vwImportingSystemTestResult.sql
Created September 5, 2017 14:30
Object fetch with joins view
create view tmp.vwImportingSystemTestResult
AS
SELECT TR.ImportingSystemTestResultId, TR.EnteredTimestamp, TR.RunTimestamp, TR.ImportingSystemTestId, TR.ImportingSystemId, TR.EnvironmentId, TR.RequesterId, TR.ImportingSystemTestExecutionStatusId,
TR.ResultFilename, Q.RequestId, DurationMs,
T.TestName, ImpSys.ImportingSystemName, E.Name, U.Username
FROM dbo.ImportingSystemTestResult TR
JOIN dbo.ImportingSystemTestRunTime TRT ON TRT.ImportingSystemTestResultId = TR.ImportingSystemTestResultId
JOIN dbo.ImportingSystemTestQueue Q ON Q.ImportingSystemTestQueueId = TR.ImportingSystemTestQueueId
-- names joins
JOIN dbo.ImportingSystemTest T ON T.ImportingSystemTestId = TR.ImportingSystemTestId
@Alexei000
Alexei000 / view_usage.cs
Created September 5, 2017 14:33
Object fetch view usage
var results = DataAccess.VwImportingSystemTestResultRepository.AllNoTracking
.Where(x => envIds.Contains(x.EnvironmentId))
.Where(x => x.EnteredTimestamp >= fromDate && x.EnteredTimestamp <= toDate)
.Take(500)
.ToList();
public class ImportingSystemTestResultOutputServiceModel
{
public int ModelIndex { get; set; }
public int ImportingSystemTestResultId { get; set; }
public DateTime EnteredTimestamp { get; set; }
public DateTime RunTimestamp { get; set; }
public int ImportingSystemTestId { get; set; }
public int ImportingSystemId { get; set; }
public int RequesterId { get; set; }
public int ImportingSystemTestExecutionStatusId { get; set; }
@Alexei000
Alexei000 / GetFilteredTestsResults.cs
Last active September 5, 2017 14:40
List fetch - get filtered tests results
public IQueryable<ImportingSystemTestResult> GetFilteredTestsResultsQuery(ImportingSystemTestResultSearchFilterServiceModel filters)
{
var dbModels = DataAccess.ImportingSystemTestResultRepository.AllNoTracking;
if (!filters.EnvironmentList.IsEmpty())
dbModels = dbModels.Where(tr => filters.EnvironmentList.Contains(tr.EnvironmentId));
if (!filters.ImportingSystemList.IsEmpty())
dbModels = dbModels.Where(tr => filters.ImportingSystemList.Contains(tr.ImportingSystemId));
// other filters come here
return dbModels;
}
@Alexei000
Alexei000 / ImportingSystemTestResultViewModel.cs
Last active September 5, 2017 15:20
List fetch - Importing system test result view model
public class ImportingSystemTestResultViewModel
{
// used internally to provide indexing if model is within a list of models
public int ModelIndex { get; set; }
public int ImportingSystemTestResultId { get; set; }
public DateTime EnteredTimestamp { get; set; }
public string EnteredTimestampStr => EnteredTimestamp.GetDateTimeDefaultString();
public DateTime RunTimestamp { get; set; }
@Alexei000
Alexei000 / GetFilteredTestsResults_usage.cs
Created September 5, 2017 15:23
Fetch list - get filtered results mapping
var serviceModel = ImportingSystemTestResultService.GetFilteredTestsResults(filters);
var viewModel = MappingService.MapListWithTotalCountModels<
ImportingSystemTestResultOutputServiceModel,
ImportingSystemTestResultViewModel,
ListWithTotalCountServiceModel<ImportingSystemTestResultOutputServiceModel>,
ListWithTotalCountViewModel<ImportingSystemTestResultViewModel>>
(serviceModel, MappingConfig.Mapper);
@Alexei000
Alexei000 / MappingService.cs
Created September 6, 2017 10:11
Object list fetch - mapping service
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AutoMapper;
using Common.Web;
using MdwAutomaticTesting.Models;
namespace MdwAutomaticTesting.Services
@Alexei000
Alexei000 / TeradataDataAccess.cs
Created September 21, 2017 11:18
Execute SQL statement with timeout
private void RegisterCommandCancelOnToken(CancellationTokenSource cts, TdCommand command)
{
if (cts == null)
return;
var innerCommand = command;
cts.Token.Register(() =>
{
try
@Alexei000
Alexei000 / IRepository.cs
Last active March 28, 2018 14:58
Generic repository interface
public interface IRepository<T> : IRepository
where T : BaseModel, new()
{
/// <summary>
/// specifies if current repository is cached
/// </summary>
bool IsCached { get; }
/// <summary>
/// gets all non-tracked items as IQueryable reference