PE_PRN212_SU24TrialTest_Note
PE_PRN212_SU24TrialTest_Note
SUMMER 2024
Subject: PRN212
INSTRUCTIONS
Please read the instructions carefully before doing the questions.
You are NOT allowed to use any other materials. You are NOT allowed to use any device to share data
with others.
You must use IDE as Visual Studio 2019 or later, MSSQL Server 2016 or later database for your
development tools.
IMPORTANT – Before you start doing your solution, MUST do the following steps:
1. To do your program, you must use Windows Presentation Foundation (WPF), apply 3-Layer
architecture. Note that you are not allowed to connect direct to database from WPF Windows/Pages,
every database connection must be used with Repository and Data Access Objects. The database
connection string must get from appsettings.json file. In the case your program connects directly to
database from WPF Windows/Pages or you hardcode connection string, you will get 0 point.
2. If there are syntax errors or compilation errors in your PE program, you will not pass the PE
requirements, the point will be 0.
3. Create Solution in Visual Studio 2019/2022 named PE_PRN212_SU24TrialTest_StudentName.
Inside the Solution, Project WPF named: AirConditionerShop_StudentName.
4. Create your MS SQL database named AirConditionerShop2024DB by running code in script
AirConditionerShop2024DB.sql.
5. Set the default user interface for your project as Login window/page.
6. Your work will be considered invalid (0 point) if your code inserts stuff that is unrelated to the test.
1
REFERENCES (this session just for reference, student can use the other approach to do Practical Exam)
Microsoft.EntityFrameworkCore.SqlServer Microsoft.Extensions.Configuration,
version Microsoft.Extensions.Configuration.Json version
.NET 5 5.0.17 5.0.0
.NET 6 6.0.27 6.0.1/6.0.0
.NET 7 7.0.16 7.0.0
.NET 8 8.0.2 8.0.0
- Install package using Tools NuGet Package Manager Package Manager Console
d. Using ConfigurationBuilder to init Configuration object for reading appsettings.json file same as this code:
private string GetConnectionString()
{
IConfiguration config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json",true,true)
.Build();
var strConn = config["ConnectionStrings:DefaultConnectionStringDB"];
return strConn;
}
e. After that, durring development, student can bypass the ConnectionString (which read from
appsettings.json) to Data access layer by constructor or others
public partial class AirConditionerShop2024DBContext: DbContext
{
public AirConditionerShop2024DBContext (string connectionString)
{
this.Database.SetConnectionString(connectionString);
}
}
- Use Entity Framework Core to generate Object Model from existing database – CLI
dotnet ef dbcontext scaffold
"Server=(local);uid=sa;pwd=100104;database=AirConditionerShop2024DB;TrustServerCertificate=True"
Microsoft.EntityFrameworkCore.SqlServer --output-dir Entites