Skip to content

Commit 6ed60fb

Browse files
committed
Generic Repository pattern
1 parent ef145ae commit 6ed60fb

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Linq.Expressions;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Tigernet.Hosting.Models.Common;
7+
8+
namespace Tigernet.Hosting.DataAccess.Generics
9+
{
10+
public interface IRepository<TEntity, TKey> where TEntity : Auditable<TKey>
11+
{
12+
IQueryable<TEntity> SelectAll();
13+
ValueTask<TEntity> SelectAsync(Expression<Func<TEntity, bool>> expression = null);
14+
ValueTask<TEntity> InsertAsync(TEntity entity);
15+
ValueTask<TEntity> UpdateAsync(TEntity entity);
16+
ValueTask<bool> DeleteAsync(Expression<Func<TEntity, bool>> expression);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
5+
using System.Threading.Tasks;
6+
using Tigernet.Hosting.Models.Common;
7+
8+
namespace Tigernet.Hosting.DataAccess.Generics
9+
{
10+
public class Repository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : Auditable<TKey>
11+
{
12+
public ValueTask<bool> DeleteAsync(Expression<Func<TEntity, bool>> expression)
13+
{
14+
throw new NotImplementedException();
15+
}
16+
17+
public ValueTask<TEntity> InsertAsync(TEntity entity)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public IQueryable<TEntity> SelectAll()
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
public ValueTask<TEntity> SelectAsync(Expression<Func<TEntity, bool>> expression = null)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
32+
public ValueTask<TEntity> UpdateAsync(TEntity entity)
33+
{
34+
throw new NotImplementedException();
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Tigernet.Hosting.Models.Common
7+
{
8+
public class Auditable<TKey>
9+
{
10+
public TKey Id { get; set; }
11+
public DateTime CreatedAt { get; set; }
12+
public DateTime? UpdatedAt { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)