-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadRepository.cs
More file actions
38 lines (29 loc) · 1.08 KB
/
Copy pathReadRepository.cs
File metadata and controls
38 lines (29 loc) · 1.08 KB
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
using ETicaretAPI.Application.Repositories;
using ETicaretAPI.Domain.Entities.Common;
using ETicaretAPI.Persistence.Contexts;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace ETicaretAPI.Persistence.Repositories
{
public class ReadRepository<T> : IReadRepository<T> where T : BaseEntity
{
private readonly ETicaretAPIDbContext _context;
public ReadRepository(ETicaretAPIDbContext context)
{
_context = context;
}
public DbSet<T> Table => _context.Set<T>();
public IQueryable<T> GetAll() => Table;
public IQueryable<T> GetWhere(Expression<Func<T, bool>> method)
=> Table.Where(method);
public async Task<T> GetSingleAsync(Expression<Func<T, bool>> method)
=> await Table.FirstOrDefaultAsync(method);
public async Task<T> GetByIdAsync(string id)
=> await Table.FirstOrDefaultAsync(data => data.Id == Guid.Parse(id));
}
}