If not, how can I associate the two tables with the key?
The class that uses is :
public class SuiviBE
{
[Key]
public int SuiviBEId { get; set; }
...
public List<ActionItem>? ActionItems { get; set; }
}
public class ActionItem
{
public int ActionItemId { get; set; }
..
public int SuiviBEId { get; set; }
public SuiviBE SuiviBE { get; set; }
}
I call the method
ActionItem act = new ActionItem();
IEnumerable<SuiviBE>? developers;
[Parameter] public int suivibeId { get; set; }
[Parameter] public int ActionItemId { get; set; }
async Task CreateActionList()
{
act.SuiviBEId = suivibeId;
await client.PutAsJsonAsync($"api/etude/{suivibeId}", act);
await client.PostAsJsonAsync($"api/etude/{suivibeId}", act);
await client.GetAsync($"api/etude/{suivibeId}");
uriHelper.NavigateTo($"/etude");
}
Right now, when I've put the breakpoint suivibeId = 0
Now how I can link dev.SuiviBEId with suivibeId?
The KeyProperty is used for something different not related to what you are trying to achieve. Better check the source code of the component for reference.
Include() method is the way to tell EF to expand (populate) sub properties (both collections and navigation properties).
In this demo for example the master DataGrid will list orders and every Order have OrderDetails which is populated in a single request using Include():
You can also populate the child records manually as shown in this demo:
Hi, I come back to you because there are some questions.
As you understood, I want to rendering the datagrid (child) un the master datagrid.
To do tthat I've created FK one to many.
The configuration of my code is :
Get Method
[HttpGet]
public async Task<IActionResult> Get()
{
var devs = await _context.SuiviBEs.Include(a => a.ActionItems).ToListAsync();
return Ok(devs);
}
With this configuration there is a message error :
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Response status code does not indicate success: 500 (Internal Server Error).
System.Net.Http.HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at System.Net.Http.Json.HttpClientJsonExtensions.d__13`1[[ServiceDT.Shared.Models.SuiviBE[], ServiceDT.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
at ServiceDT.Client.Pages.Etude.OnInitializedAsync() in C:\App\sbd\ServiceDT\ServiceDT\Client\Pages\Etude.razor:line 217
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
If I modify the GEt method w/o include() as below, there are any error but the child table is not rendering.
[HttpGet]
public async Task<IActionResult> Get()
{
var devs = await _context.SuiviBEs.ToListAsync();
return Ok(devs);
}
If I put a breakpoint on get method the FK one to many is well populated.