Skip to content

Commit bcfb009

Browse files
authored
1115 Discord Bot intro (csharpfritz#96)
* Pre-stream demo * Added token image * Added more content * Update README.md * WIP
1 parent 4dc7d3b commit bcfb009

File tree

63 files changed

+1674
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1674
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace MyBlogApp;
4+
5+
public class AppDbContext : DbContext
6+
{
7+
8+
public DbSet<BlogPost> Posts { get; set; }
9+
10+
public DbSet<Author> Authors { get; set; }
11+
12+
public DbSet<Tag> Tags { get; set; }
13+
14+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
15+
{
16+
17+
var conn = @"Data Source=appdb.db;";
18+
optionsBuilder.UseSqlite(conn);
19+
// .LogTo(x => Console.WriteLine($"Db: '{x}'"));
20+
21+
base.OnConfiguring(optionsBuilder);
22+
}
23+
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MyBlogApp;
2+
3+
public class Author {
4+
5+
public int Id { get; set; }
6+
7+
public string Name { get; set; }
8+
9+
public string EmailAddress { get; set; }
10+
11+
public List<BlogPost> BlogPosts { get; set; }
12+
13+
public override string ToString() {
14+
return $"{Name} <{EmailAddress}>";
15+
}
16+
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace MyBlogApp;
4+
5+
public class BlogPost {
6+
7+
public int Id { get; set; }
8+
9+
public string Title { get; set; }
10+
11+
public DateTime PublishedUtc { get; set; }
12+
13+
public string Content { get; set; }
14+
15+
public Author Author { get; set; }
16+
17+
public ICollection<Tag> Tags { get; set; } = new List<Tag>();
18+
19+
public override string ToString() {
20+
return $"{Title} ({Id})";
21+
}
22+
23+
}

sessions/Season-01/0112-EfCore/MyBlogApp/Migrations/20211122152614_First.Designer.cs

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace MyBlogApp.Migrations
7+
{
8+
public partial class First : Migration
9+
{
10+
protected override void Up(MigrationBuilder migrationBuilder)
11+
{
12+
migrationBuilder.CreateTable(
13+
name: "Posts",
14+
columns: table => new
15+
{
16+
Id = table.Column<int>(type: "INTEGER", nullable: false)
17+
.Annotation("Sqlite:Autoincrement", true),
18+
Title = table.Column<string>(type: "TEXT", nullable: true),
19+
PublishedUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
20+
Content = table.Column<string>(type: "TEXT", nullable: true)
21+
},
22+
constraints: table =>
23+
{
24+
table.PrimaryKey("PK_Posts", x => x.Id);
25+
});
26+
}
27+
28+
protected override void Down(MigrationBuilder migrationBuilder)
29+
{
30+
migrationBuilder.DropTable(
31+
name: "Posts");
32+
}
33+
}
34+
}

sessions/Season-01/0112-EfCore/MyBlogApp/Migrations/20211129153227_Add Authors.Designer.cs

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace MyBlogApp.Migrations
6+
{
7+
public partial class AddAuthors : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.AddColumn<int>(
12+
name: "AuthorId",
13+
table: "Posts",
14+
type: "INTEGER",
15+
nullable: true);
16+
17+
migrationBuilder.CreateTable(
18+
name: "Authors",
19+
columns: table => new
20+
{
21+
Id = table.Column<int>(type: "INTEGER", nullable: false)
22+
.Annotation("Sqlite:Autoincrement", true),
23+
Name = table.Column<string>(type: "TEXT", nullable: true),
24+
EmailAddress = table.Column<string>(type: "TEXT", nullable: true)
25+
},
26+
constraints: table =>
27+
{
28+
table.PrimaryKey("PK_Authors", x => x.Id);
29+
});
30+
31+
migrationBuilder.CreateIndex(
32+
name: "IX_Posts_AuthorId",
33+
table: "Posts",
34+
column: "AuthorId");
35+
36+
migrationBuilder.AddForeignKey(
37+
name: "FK_Posts_Authors_AuthorId",
38+
table: "Posts",
39+
column: "AuthorId",
40+
principalTable: "Authors",
41+
principalColumn: "Id");
42+
}
43+
44+
protected override void Down(MigrationBuilder migrationBuilder)
45+
{
46+
migrationBuilder.DropForeignKey(
47+
name: "FK_Posts_Authors_AuthorId",
48+
table: "Posts");
49+
50+
migrationBuilder.DropTable(
51+
name: "Authors");
52+
53+
migrationBuilder.DropIndex(
54+
name: "IX_Posts_AuthorId",
55+
table: "Posts");
56+
57+
migrationBuilder.DropColumn(
58+
name: "AuthorId",
59+
table: "Posts");
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)