I'm new to Blazor and I'm having a bit of a problem with my Data Access Layer Model. I created a database and I double checked all my keys and foreign keys to make sure they are correct. I imported the model (Reverser Engineer) using EF Core Power Tools but I can't seem to get my Models to connect via the FK's. For Example.
To keep it simple -
Company Table
ID - PK
CompanyName - varchar
Employee Table
ID - PK
Name - varchar
CompanyEmployee Table
ID - PK
CompanyID -FK
EmployeeID - FK
in my blazor c# code
@if(companyEmployees != null @@ companyEmployees .Count > 0)
{
@foreach(var item in companyEmployees)
{
<h4>@item.Employee.Name</h4> // < ---- ERROR HERE Because Employee is NULL
}
}
@code
{
List<CompanyEmployee> companyEmployees = null;
protected override async Task OnInitializedAsync()
{
using(DbContext context = new DbContext())
{
companyEmployees =
await context.CompanyEmployee.Where(c => c.CompanyId == 1).ToListAsync(); // so get all the employee ID from the company that has the ID=1
}
}
}
where i commented above the error. I'm getting all the employee CompanyEmployee objects but the Employee object in my foreach statements are null. It's like the Foreign Keys aren't talking to each other.
Anyone have thoughts?
