Hi @Ahmed Salah Abed Elaziz
Welcome to Asp.net core Q&A forum.
To your issue, you can add a navigation property in the ServerNames model and configure the ServerNames and ServerTypes with One-to-one relationship. After that when query the ServerNames, you can use the Include method to load the related ServerTypes model, after that, you can display the server type based on the navigation property. Code like below:
Add the navigation property in the ServerNames model:
public class ServerNames
{
[Key]
public int ServerID { get; set; }
public string ServerName { get; set; }
public int ServerTypeId { get; set; }
[ForeignKey("ServerTypeId")]
public virtual ServerTypes ServerTypes { get; set; }
}
Then, in the ServerNamesServices GetAll method, query the database and use Include method to load the ServerNames with ServerTypes:
public interface IserverNamesService : IRepository<ServerNames>
{
}
public class ServerNamesServices : IserverNamesService
{
private readonly TestDbContext _context;
public ServerNamesServices(TestDbContext testDbContext) {
_context = testDbContext;
}
public IEnumerable<ServerNames> GetAll()
{
return _context.ServerNames.Include(c=>c.ServerTypes).ToList();
}
}
register the service in the program.cs file, like this:
builder.Services.AddScoped<IserverNamesService, ServerNamesServices>();
In the Blazor component: in the select statement, create the ServerNamesClass entity based on the query result:
@page "/serverpage"
<PageTitle>Server Name List</PageTitle>
@using BlazorServerApp.Data
@using BlazorServerApp.Services
@inject IserverNamesService servernameService
@if (servernameclasses == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Server ID</th>
<th>Server Name</th>
<th>Server Type</th>
</tr>
</thead>
<tbody>
@foreach (var servername in servernameclasses)
{
<tr class="draggable"
data-id="1001"
id="row1"
tabindex="1">
<td>@servername.serverID</td>
<td>@servername.serverName</td>
<td>@servername.serverType</td>
</tr>
}
</tbody>
</table>
}
@code {
private List<ServerNamesClass> servernameclasses;
protected override async Task OnInitializedAsync()
{
servernameclasses = servernameService.GetAll().Select(c =>
new ServerNamesClass() {
serverID = c.ServerID,
serverName = c.ServerName,
serverType = c.ServerTypes.ServerType })
.ToList();
}
}
The database table:

the result as below:

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion