-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
Query.cs
36 lines (31 loc) · 1.13 KB
/
Query.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
using System.Linq;
using System.Threading.Tasks;
using HotChocolate.Types;
using Microsoft.EntityFrameworkCore;
namespace HotChocolate.Data
{
public class Query
{
[UseDbContext(typeof(BookContext))]
public IQueryable<Author> GetAuthors([ScopedService]BookContext context) =>
context.Authors;
[UseDbContext(typeof(BookContext))]
public async Task<Author> GetAuthor([ScopedService]BookContext context) =>
await context.Authors.FirstOrDefaultAsync();
[UseDbContext(typeof(BookContext))]
[UseOffsetPaging(IncludeTotalCount = true)]
[UseFiltering]
[UseSorting]
public IQueryable<Author> GetAuthorOffsetPaging([ScopedService]BookContext context) =>
context.Authors;
}
public class InvalidQuery
{
[UseDbContext(typeof(object))]
public IQueryable<Author> GetAuthors([ScopedService]BookContext context) =>
context.Authors;
[UseDbContext(typeof(object))]
public async Task<Author> GetAuthor([ScopedService]BookContext context) =>
await context.Authors.FirstOrDefaultAsync();
}
}