MapEdgeRepository.cs
1.93 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;
namespace Rcs.Infrastructure.DB.Repositories
{
/// <summary>
/// 地图资源仓储实现
/// </summary>
public class MapEdgeRepository : Repository<MapEdge>, IMapEdgeRepository
{
public MapEdgeRepository(AppDbContext context) : base(context)
{
}
public async Task<IEnumerable<MapEdge>> GetByMapIdAsync(Guid mapId, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(r => r.MapId == mapId && r.Active)
.ToListAsync(cancellationToken);
}
public async Task<MapEdge?> GetByMapIdAndEdgeCodeAsync(Guid mapId, string edgeCode, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(r => r.MapId == mapId && r.Active)
.Where(e => e.EdgeCode == edgeCode)
.FirstOrDefaultAsync(cancellationToken);
}
public async Task<IEnumerable<MapEdge>> GetByFromNodeAsync(Guid fromNode, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(e => e.FromNode == fromNode)
.ToListAsync(cancellationToken);
}
public async Task<IEnumerable<MapEdge>> GetByToNodeAsync(Guid toNode, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(e => e.ToNode == toNode)
.ToListAsync(cancellationToken);
}
public async Task<IEnumerable<MapEdge>> GetByFromAndToNodeAsync(Guid fromNode, Guid toNode, CancellationToken cancellationToken = default)
{
return await _dbSet
.Where(e => e.FromNode == fromNode)
.Where(e => e.ToNode == toNode)
.ToListAsync(cancellationToken);
}
}
}