示例#1
0
        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);
            }
                );
        }
示例#2
0
        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();
        }
示例#3
0
 public GraphQLController(ApplicationCtx db) => _db = db;
示例#4
0
 public EfMysqlPostRepository(ApplicationCtx context) => Context = context;
示例#5
0
 public EfMysqlCommentRepository(ApplicationCtx ctx)
 {
     Context = ctx;
 }