diff --git a/Controllers/PeopleController.cs b/Controllers/PeopleController.cs
index 919c3e7..1ca1f91 100644
--- a/Controllers/PeopleController.cs
+++ b/Controllers/PeopleController.cs
@@ -12,13 +12,31 @@ namespace contacts.Controllers
public class PeopleController : ControllerBase
{
[HttpGet]
+ // public Person[] Get()
public Person[] Get()
{
- Person p1 = new Person(1, "Matt", 40);
- Person p2 = new Person(2, "Sally", 32);
- Person p3 = new Person(3, "Zagthrop", 834);
- // Console.WriteLine(p1.name);
- return new Person[] { p1, p2, p3 };
+ using (var db = new PeopleContext())
+ {
+ // Console.WriteLine("Hello World!");
+ // db.Add(new Person { Name = "Matt", Age = 40 });
+ // db.SaveChanges();
+
+ // var person = db.People
+ var people = db.People
+ .OrderBy(person => person.PersonId)
+ // .Last();
+ .ToArray();
+ // Console.WriteLine(person.Age);
+ Console.WriteLine(db.People.OrderBy(person => person.PersonId).ToArray());
+
+ // return person;
+ return people;
+ }
+ // Person p1 = new Person(1, "Matt", 40);
+ // Person p2 = new Person(2, "Sally", 32);
+ // Person p3 = new Person(3, "Zagthrop", 834);
+ // // Console.WriteLine(p1.name);
+ // return new Person[] { p1, p2, p3 };
}
}
}
diff --git a/Migrations/20201017005725_InitialCreate.Designer.cs b/Migrations/20201017005725_InitialCreate.Designer.cs
new file mode 100644
index 0000000..b22ba80
--- /dev/null
+++ b/Migrations/20201017005725_InitialCreate.Designer.cs
@@ -0,0 +1,39 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using contacts;
+
+namespace contacts.Migrations
+{
+ [DbContext(typeof(PeopleContext))]
+ [Migration("20201017005725_InitialCreate")]
+ partial class InitialCreate
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "3.1.9");
+
+ modelBuilder.Entity("contacts.Person", b =>
+ {
+ b.Property("PersonId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Age")
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.HasKey("PersonId");
+
+ b.ToTable("People");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Migrations/20201017005725_InitialCreate.cs b/Migrations/20201017005725_InitialCreate.cs
new file mode 100644
index 0000000..baf512b
--- /dev/null
+++ b/Migrations/20201017005725_InitialCreate.cs
@@ -0,0 +1,30 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace contacts.Migrations
+{
+ public partial class InitialCreate : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "People",
+ columns: table => new
+ {
+ PersonId = table.Column(nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Name = table.Column(nullable: true),
+ Age = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_People", x => x.PersonId);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "People");
+ }
+ }
+}
diff --git a/Migrations/PeopleContextModelSnapshot.cs b/Migrations/PeopleContextModelSnapshot.cs
new file mode 100644
index 0000000..d82bba3
--- /dev/null
+++ b/Migrations/PeopleContextModelSnapshot.cs
@@ -0,0 +1,37 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using contacts;
+
+namespace contacts.Migrations
+{
+ [DbContext(typeof(PeopleContext))]
+ partial class PeopleContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "3.1.9");
+
+ modelBuilder.Entity("contacts.Person", b =>
+ {
+ b.Property("PersonId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Age")
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.HasKey("PersonId");
+
+ b.ToTable("People");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Model.cs b/Model.cs
new file mode 100644
index 0000000..2423420
--- /dev/null
+++ b/Model.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore;
+
+namespace contacts
+{
+ public class PeopleContext : DbContext
+ {
+ public DbSet People { get; set; }
+
+ protected override void OnConfiguring(DbContextOptionsBuilder options)
+ => options.UseSqlite("Data Source=people.db");
+ }
+
+ public class Person
+ {
+ public int PersonId { get; set; }
+ public string Name { get; set; }
+ public int Age { get; set; }
+ }
+}
diff --git a/Person.cs b/Person.cs
deleted file mode 100644
index 65fb02f..0000000
--- a/Person.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-
-namespace contacts
-{
- public class Person
- {
- public int id { get; set; }
- public string name { get; set; }
- public int age { get; set; }
- public Person(int idParam, string nameParam, int ageParam)
- {
-
- this.id = idParam;
- this.name = nameParam;
- this.age = ageParam;
- }
- }
-}
diff --git a/contacts.csproj b/contacts.csproj
index 13f684e..5e56310 100644
--- a/contacts.csproj
+++ b/contacts.csproj
@@ -11,6 +11,11 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
diff --git a/people.db b/people.db
new file mode 100644
index 0000000..8032d86
Binary files /dev/null and b/people.db differ