tgstation-server 6.19.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;
6
7using Microsoft.EntityFrameworkCore;
8
10{
12 sealed class DatabaseCollection<TModel> : IDatabaseCollection<TModel>
13 where TModel : class
14 {
18 readonly DbSet<TModel> dbSet;
19
24 public DatabaseCollection(DbSet<TModel> dbSet)
25 {
26 this.dbSet = dbSet ?? throw new ArgumentNullException(nameof(dbSet));
27 }
28
30 public IEnumerable<TModel> Local => dbSet.Local;
31
33 public Type ElementType => dbSet.AsQueryable().ElementType;
34
36 public Expression Expression => dbSet.AsQueryable().Expression;
37
39 public IQueryProvider Provider => dbSet.AsQueryable().Provider;
40
42 public void Add(TModel model) => dbSet.Add(model);
43
45 public void AddRange(IEnumerable<TModel> models) => dbSet.AddRange(models);
46
48 public void Attach(TModel model) => dbSet.Attach(model);
49
51 public IEnumerator<TModel> GetEnumerator() => dbSet.AsQueryable().GetEnumerator();
52
54 public void Remove(TModel model) => dbSet.Remove(model);
55
57 public void RemoveRange(IEnumerable<TModel> models) => dbSet.RemoveRange(models);
58
60 IEnumerator IEnumerable.GetEnumerator() => dbSet.AsQueryable().GetEnumerator();
61 }
62}
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>.