forked from urfnet/URF.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service.cs
84 lines (61 loc) · 3.67 KB
/
Service.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using TrackableEntities.Common.Core;
using URF.Core.Abstractions;
using URF.Core.Abstractions.Services;
using URF.Core.Abstractions.Trackable;
namespace URF.Core.Services
{
public abstract class Service<TEntity> : IService<TEntity> where TEntity : class, ITrackable
{
protected readonly ITrackableRepository<TEntity> Repository;
protected Service(ITrackableRepository<TEntity> repository)
=> Repository = repository;
public virtual void Attach(TEntity item)
=> Repository.Attach(item);
public virtual void Delete(TEntity item)
=> Repository.Delete(item);
public virtual async Task<bool> DeleteAsync(object[] keyValues, CancellationToken cancellationToken = default)
=> await Repository.DeleteAsync(keyValues, cancellationToken);
public virtual async Task<bool> DeleteAsync<TKey>(TKey keyValue, CancellationToken cancellationToken = default)
=> await Repository.DeleteAsync(keyValue, cancellationToken);
public virtual void Detach(TEntity item)
=> Repository.Detach(item);
public virtual async Task<bool> ExistsAsync(object[] keyValues, CancellationToken cancellationToken = default)
=> await Repository.ExistsAsync(keyValues, cancellationToken);
public virtual async Task<bool> ExistsAsync<TKey>(TKey keyValue, CancellationToken cancellationToken = default)
=> await Repository.ExistsAsync(keyValue, cancellationToken);
public virtual async Task<TEntity> FindAsync(object[] keyValues, CancellationToken cancellationToken = default)
=> await Repository.FindAsync(keyValues, cancellationToken);
public virtual async Task<TEntity> FindAsync<TKey>(TKey keyValue, CancellationToken cancellationToken = default)
=> await Repository.FindAsync(keyValue, cancellationToken);
public virtual void Insert(TEntity item)
=> Repository.Insert(item);
public virtual async Task LoadPropertyAsync(TEntity item, Expression<Func<TEntity, object>> property, CancellationToken cancellationToken = default)
=> await Repository.LoadPropertyAsync(item, property, cancellationToken);
public virtual IQuery<TEntity> Query()
=> Repository.Query();
public virtual IQueryable<TEntity> Queryable()
=> Repository.Queryable();
public virtual IQueryable<TEntity> QueryableSql(string sql, params object[] parameters)
=> Repository.QueryableSql(sql, parameters);
public virtual async Task<IEnumerable<TEntity>> SelectAsync(CancellationToken cancellationToken = default)
=> await Repository.Query().SelectAsync(cancellationToken);
public virtual async Task<IEnumerable<TEntity>> SelectSqlAsync(string sql, object[] parameters, CancellationToken cancellationToken = default)
=> await Repository.Query().SelectSqlAsync(sql, parameters, cancellationToken);
public virtual void Update(TEntity item)
=> Repository.Update(item);
public virtual void ApplyChanges(params TEntity[] entities)
=> Repository.ApplyChanges(entities);
public virtual void AcceptChanges(params TEntity[] entities)
=> Repository.AcceptChanges(entities);
public virtual void DetachEntities(params TEntity[] entities)
=> Repository.DetachEntities(entities);
public virtual async Task LoadRelatedEntities(params TEntity[] entities)
=> await Repository.LoadRelatedEntities(entities);
}
}