tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DatabaseCollection.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Linq;
5using System.Linq.Expressions;
6using System.Threading;
7
8using Microsoft.EntityFrameworkCore;
9
11{
13 sealed class DatabaseCollection<TModel> : IDatabaseCollection<TModel>
14 where TModel : class
15 {
19 readonly DbSet<TModel> dbSet;
20
25 public DatabaseCollection(DbSet<TModel> dbSet)
26 {
27 this.dbSet = dbSet ?? throw new ArgumentNullException(nameof(dbSet));
28 }
29
31 public IEnumerable<TModel> Local => dbSet.Local;
32
34 public Type ElementType => dbSet.AsQueryable().ElementType;
35
37 public Expression Expression => dbSet.AsQueryable().Expression;
38
40 public IQueryProvider Provider => dbSet.AsQueryable().Provider;
41
43 public void Add(TModel model) => dbSet.Add(model);
44
46 public void AddRange(IEnumerable<TModel> models) => dbSet.AddRange(models);
47
49 public void Attach(TModel model) => dbSet.Attach(model);
50
52 public IAsyncEnumerator<TModel> GetAsyncEnumerator(CancellationToken cancellationToken = default) => dbSet.AsAsyncEnumerable().GetAsyncEnumerator(cancellationToken);
53
55 public IEnumerator<TModel> GetEnumerator() => dbSet.AsQueryable().GetEnumerator();
56
58 public void Remove(TModel model) => dbSet.Remove(model);
59
61 public void RemoveRange(IEnumerable<TModel> models) => dbSet.RemoveRange(models);
62
64 IEnumerator IEnumerable.GetEnumerator() => dbSet.AsQueryable().GetEnumerator();
65 }
66}
IAsyncEnumerator< TModel > GetAsyncEnumerator(CancellationToken cancellationToken=default)
void Add(TModel model)
Add a given model to the the working set.
void Attach(TModel model)
Attach a given model to the the working set.
void RemoveRange(IEnumerable< TModel > models)
Remove a range of models from the IDatabaseCollection<TModel>.
void Remove(TModel model)
Remove a given model from the the working set.
readonly DbSet< TModel > dbSet
The backing DbSet<TEntity>.
DatabaseCollection(DbSet< TModel > dbSet)
Initializes a new instance of the DatabaseCollection<TModel> class.
IEnumerable< TModel > Local
An IEnumerable<T> of TModel s prioritizing in the working set.
void AddRange(IEnumerable< TModel > models)
Add a range of models to the IDatabaseCollection<TModel>.