Skip to content

Commit 6f15b09

Browse files
Copy .NET 6 code to .NET 9 folder (#33960)
1 parent f190867 commit 6f15b09

Some content is hidden

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

65 files changed

+75438
-0
lines changed
4 KB
Binary file not shown.
32 KB
Binary file not shown.
56.4 KB
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
8+
<!-- -->
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<DefineConstants>$(DefineConstants)TRACE;SQLiteVersion</DefineConstants>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SQLite" Version="6.0.0" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#define FIRST
2+
#if FIRST // First DbInitializer used
3+
// <snippet>
4+
using ContosoUniversity.Models;
5+
6+
namespace ContosoUniversity.Data
7+
{
8+
public static class DbInitializer
9+
{
10+
public static void Initialize(SchoolContext context)
11+
{
12+
// Look for any students.
13+
if (context.Students.Any())
14+
{
15+
return; // DB has been seeded
16+
}
17+
18+
var students = new Student[]
19+
{
20+
new Student{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2019-09-01")},
21+
new Student{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2017-09-01")},
22+
new Student{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2018-09-01")},
23+
new Student{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2017-09-01")},
24+
new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2017-09-01")},
25+
new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2016-09-01")},
26+
new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2018-09-01")},
27+
new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2019-09-01")}
28+
};
29+
30+
context.Students.AddRange(students);
31+
context.SaveChanges();
32+
33+
var courses = new Course[]
34+
{
35+
new Course{CourseID=1050,Title="Chemistry",Credits=3},
36+
new Course{CourseID=4022,Title="Microeconomics",Credits=3},
37+
new Course{CourseID=4041,Title="Macroeconomics",Credits=3},
38+
new Course{CourseID=1045,Title="Calculus",Credits=4},
39+
new Course{CourseID=3141,Title="Trigonometry",Credits=4},
40+
new Course{CourseID=2021,Title="Composition",Credits=3},
41+
new Course{CourseID=2042,Title="Literature",Credits=4}
42+
};
43+
44+
context.Courses.AddRange(courses);
45+
context.SaveChanges();
46+
47+
var enrollments = new Enrollment[]
48+
{
49+
new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A},
50+
new Enrollment{StudentID=1,CourseID=4022,Grade=Grade.C},
51+
new Enrollment{StudentID=1,CourseID=4041,Grade=Grade.B},
52+
new Enrollment{StudentID=2,CourseID=1045,Grade=Grade.B},
53+
new Enrollment{StudentID=2,CourseID=3141,Grade=Grade.F},
54+
new Enrollment{StudentID=2,CourseID=2021,Grade=Grade.F},
55+
new Enrollment{StudentID=3,CourseID=1050},
56+
new Enrollment{StudentID=4,CourseID=1050},
57+
new Enrollment{StudentID=4,CourseID=4022,Grade=Grade.F},
58+
new Enrollment{StudentID=5,CourseID=4041,Grade=Grade.C},
59+
new Enrollment{StudentID=6,CourseID=1045},
60+
new Enrollment{StudentID=7,CourseID=3141,Grade=Grade.A},
61+
};
62+
63+
context.Enrollments.AddRange(enrollments);
64+
context.SaveChanges();
65+
}
66+
}
67+
}
68+
// </snippet>
69+
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#define First // LAST First
2+
#if First
3+
// <snippet_first>
4+
using ContosoUniversity.Models;
5+
using Microsoft.EntityFrameworkCore;
6+
7+
namespace ContosoUniversity.Data
8+
{
9+
public class SchoolContext : DbContext
10+
{
11+
public SchoolContext (DbContextOptions<SchoolContext> options)
12+
: base(options)
13+
{
14+
}
15+
16+
public DbSet<Student> Students { get; set; }
17+
public DbSet<Enrollment> Enrollments { get; set; }
18+
public DbSet<Course> Courses { get; set; }
19+
20+
protected override void OnModelCreating(ModelBuilder modelBuilder)
21+
{
22+
modelBuilder.Entity<Course>().ToTable("Course");
23+
modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
24+
modelBuilder.Entity<Student>().ToTable("Student");
25+
}
26+
}
27+
}
28+
// </snippet_first>
29+
#elif LAST
30+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#define FIRST
2+
#if FIRST
3+
// <snippet_first>
4+
using System.ComponentModel.DataAnnotations.Schema;
5+
6+
namespace ContosoUniversity.Models
7+
{
8+
public class Course
9+
{
10+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
11+
public int CourseID { get; set; }
12+
public string Title { get; set; }
13+
public int Credits { get; set; }
14+
15+
public ICollection<Enrollment> Enrollments { get; set; }
16+
}
17+
}
18+
// </snippet_first>
19+
#elif LAST
20+
using System.ComponentModel.DataAnnotations;
21+
using System.ComponentModel.DataAnnotations.Schema;
22+
23+
namespace ContosoUniversity.Models
24+
{
25+
// <snippet_last>
26+
public class Course
27+
{
28+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
29+
[Display(Name = "Number")]
30+
public int CourseID { get; set; }
31+
32+
[StringLength(50, MinimumLength = 3)]
33+
public string Title { get; set; }
34+
35+
[Range(0, 5)]
36+
public int Credits { get; set; }
37+
38+
public int DepartmentID { get; set; }
39+
40+
public Department Department { get; set; }
41+
public ICollection<Enrollment> Enrollments { get; set; }
42+
public ICollection<Instructor> Instructors { get; set; }
43+
}
44+
}
45+
// </snippet_last>
46+
#endif
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#define FIRST
2+
#if FIRST
3+
// <snippet1>
4+
using System.ComponentModel.DataAnnotations;
5+
using System.ComponentModel.DataAnnotations.Schema;
6+
7+
namespace ContosoUniversity.Models
8+
{
9+
public class Department
10+
{
11+
public int DepartmentID { get; set; }
12+
13+
[StringLength(50, MinimumLength = 3)]
14+
public string Name { get; set; }
15+
16+
[DataType(DataType.Currency)]
17+
[Column(TypeName = "money")]
18+
public decimal Budget { get; set; }
19+
20+
[DataType(DataType.Date)]
21+
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
22+
ApplyFormatInEditMode = true)]
23+
[Display(Name = "Start Date")]
24+
public DateTime StartDate { get; set; }
25+
26+
public int? InstructorID { get; set; }
27+
28+
public Instructor Administrator { get; set; }
29+
public ICollection<Course> Courses { get; set; }
30+
}
31+
}
32+
// </snippet1>
33+
#else
34+
#if SQLiteVersion
35+
// <snippetSL>
36+
using System;
37+
using System.Collections.Generic;
38+
using System.ComponentModel.DataAnnotations;
39+
using System.ComponentModel.DataAnnotations.Schema;
40+
41+
namespace ContosoUniversity.Models
42+
{
43+
public class Department
44+
{
45+
public int DepartmentID { get; set; }
46+
47+
[StringLength(50, MinimumLength = 3)]
48+
public string Name { get; set; }
49+
50+
[DataType(DataType.Currency)]
51+
[Column(TypeName = "money")]
52+
public decimal Budget { get; set; }
53+
54+
[DataType(DataType.Date)]
55+
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
56+
ApplyFormatInEditMode = true)]
57+
[Display(Name = "Start Date")]
58+
public DateTime StartDate { get; set; }
59+
60+
public int? InstructorID { get; set; }
61+
62+
public Guid ConcurrencyToken { get; set; } = Guid.NewGuid();
63+
64+
public Instructor Administrator { get; set; }
65+
public ICollection<Course> Courses { get; set; }
66+
}
67+
}
68+
// </snippetSL>
69+
#else // SQL Server version with concurrency token
70+
// <snippet3>
71+
using System;
72+
using System.Collections.Generic;
73+
using System.ComponentModel.DataAnnotations;
74+
using System.ComponentModel.DataAnnotations.Schema;
75+
76+
namespace ContosoUniversity.Models
77+
{
78+
public class Department
79+
{
80+
public int DepartmentID { get; set; }
81+
82+
[StringLength(50, MinimumLength = 3)]
83+
public string Name { get; set; }
84+
85+
[DataType(DataType.Currency)]
86+
[Column(TypeName = "money")]
87+
public decimal Budget { get; set; }
88+
89+
[DataType(DataType.Date)]
90+
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
91+
ApplyFormatInEditMode = true)]
92+
[Display(Name = "Start Date")]
93+
public DateTime StartDate { get; set; }
94+
95+
public int? InstructorID { get; set; }
96+
97+
[Timestamp]
98+
public byte[] ConcurrencyToken { get; set; }
99+
100+
public Instructor Administrator { get; set; }
101+
public ICollection<Course> Courses { get; set; }
102+
}
103+
}
104+
// </snippet3>
105+
#endif
106+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace ContosoUniversity.Models
4+
{
5+
public enum Grade
6+
{
7+
A, B, C, D, F
8+
}
9+
10+
public class Enrollment
11+
{
12+
public int EnrollmentID { get; set; }
13+
public int CourseID { get; set; }
14+
public int StudentID { get; set; }
15+
[DisplayFormat(NullDisplayText = "No grade")]
16+
public Grade? Grade { get; set; }
17+
18+
public Course Course { get; set; }
19+
public Student Student { get; set; }
20+
}
21+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//#define BeforeInheritance
2+
#if BeforeInheritance
3+
// <snippet_BeforeInheritance>
4+
using System;
5+
using System.Collections.Generic;
6+
using System.ComponentModel.DataAnnotations;
7+
using System.ComponentModel.DataAnnotations.Schema;
8+
9+
namespace ContosoUniversity.Models
10+
{
11+
public class Instructor
12+
{
13+
public int ID { get; set; }
14+
15+
[Required]
16+
[Display(Name = "Last Name")]
17+
[StringLength(50)]
18+
public string LastName { get; set; }
19+
20+
[Required]
21+
[Column("FirstName")]
22+
[Display(Name = "First Name")]
23+
[StringLength(50)]
24+
public string FirstMidName { get; set; }
25+
26+
[DataType(DataType.Date)]
27+
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
28+
[Display(Name = "Hire Date")]
29+
public DateTime HireDate { get; set; }
30+
31+
[Display(Name = "Full Name")]
32+
public string FullName
33+
{
34+
get { return LastName + ", " + FirstMidName; }
35+
}
36+
37+
public ICollection<Course> Courses { get; set; }
38+
public OfficeAssignment OfficeAssignment { get; set; }
39+
}
40+
}
41+
// </snippet_BeforeInheritance>
42+
#else
43+
using System;
44+
using System.Collections.Generic;
45+
using System.ComponentModel.DataAnnotations;
46+
using System.ComponentModel.DataAnnotations.Schema;
47+
48+
namespace ContosoUniversity.Models
49+
{
50+
public class Instructor : Person
51+
{
52+
[DataType(DataType.Date)]
53+
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
54+
[Display(Name = "Hire Date")]
55+
public DateTime HireDate { get; set; }
56+
57+
[Display(Name = "Full Name")]
58+
public string FullName
59+
{
60+
get { return LastName + ", " + FirstMidName; }
61+
}
62+
63+
public ICollection<Course> Courses { get; set; }
64+
public OfficeAssignment OfficeAssignment { get; set; }
65+
}
66+
}
67+
#endif

0 commit comments

Comments
 (0)