Restructured query repositries to move ef logic from handlers
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Data.Interfaces
|
||||
{
|
||||
@@ -12,5 +13,7 @@ namespace BrightGlimmer.Data.Interfaces
|
||||
IQueryable<T> Get();
|
||||
|
||||
T Get(Guid id);
|
||||
|
||||
Task<T> GetAsync(Guid id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
@@ -27,5 +29,10 @@ namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
return context.Set<T>().Find(id);
|
||||
}
|
||||
|
||||
public virtual async Task<T> GetAsync(Guid id)
|
||||
{
|
||||
return await context.Set<T>().SingleAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,43 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class StudentQueryRepository : QueryRepository<Student>
|
||||
{
|
||||
public StudentQueryRepository(BgContext context) : base(context) { }
|
||||
|
||||
public override IQueryable<Student> Get()
|
||||
{
|
||||
return context.Students
|
||||
.Include(x => x.Phones)
|
||||
.Include(x => x.Address)
|
||||
.Include(x => x.AssignedCourses);
|
||||
}
|
||||
|
||||
public override Student Get(Guid id)
|
||||
{
|
||||
return context.Students
|
||||
.Include(x => x.Phones)
|
||||
.Include(x => x.Address)
|
||||
.Include(x => x.AssignedCourses)
|
||||
.Single(x => x.Id == id);
|
||||
}
|
||||
|
||||
public override async Task<Student> GetAsync(Guid id)
|
||||
{
|
||||
return await context.Students
|
||||
.Include(x => x.Phones)
|
||||
.Include(x => x.Address)
|
||||
.Include(x => x.AssignedCourses)
|
||||
.SingleAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user