There are several ways to do this. There is no right or wrong way. Which way you chose really depends on the architecture, complexity and the requirements of your application.
As you can see from the image, we are displaying the following employee details.
- Id
- Name
- Department Name
Id, Name, and Email come from the Employees database table and the Department Name comes from the Departments table. Here we are working with two database tables, but you can use the same technique to work with three or even more database tables.
Employee Class
The Department property carries the employee Department data i.e DepartmentId and DepartmentName.
EmployeeRepository
In the Employee entity, to include related entity data like Department, chain the Include() method. Chain ThenInclude() method if you want to include additional related entities like skills data, experience data etc.
EmployeeDetails Component
The following null check is required. Otherwise you will get a NullReferenceException, if either Employee or Department properties are not initialized by the time the view references those properties.
@if (Employee == null || Employee.Department == null) { <div class="spinner"></div> }
No comments:
Post a Comment