public AuthorQuery(ApplicationCtx db) { Field <AuthorType>( "Author", arguments: new QueryArguments( new QueryArgument <IdGraphType> { Name = "id", Description = "The ID of the Author." } ), resolve: context => { var id = context.GetArgument <int>("id"); var author = db .Authors .Include(a => a.Books) .FirstOrDefault(i => i.Id == id); return(author); } ); Field <AuthorType>( "Authors", resolve: context => { var authors = db.Authors.Include(a => a.Books); return(authors); } ); }
public static void Main(string[] args) { IHost host = CreateHostBuilder(args).Build(); // SEED the DB using (IServiceScope scope = host.Services.CreateScope()) { ApplicationCtx ctx = scope.ServiceProvider.GetRequiredService <ApplicationCtx>(); var authorDbEntry = ctx.Authors.Add( new Author { Name = "jimmyfargo", } ); ctx.SaveChanges(); ctx.Books.AddRange( new Book { Id = "1", Name = "First Book", Published = true, AuthorId = authorDbEntry.Entity.Id, Genre = "Mystery" }, new Book { Id = "2", Name = "Second Book", Published = true, AuthorId = authorDbEntry.Entity.Id, Genre = "Crime" } ); ctx.SaveChanges(); } host.Run(); }
public GraphQLController(ApplicationCtx db) => _db = db;
public EfMysqlPostRepository(ApplicationCtx context) => Context = context;
public EfMysqlCommentRepository(ApplicationCtx ctx) { Context = ctx; }