Base solution for your next web application
Open Closed

FirstOrDefaultAsync Include Problem in API #10200


User avatar
0
QuickApp created

Hi, I am using the FirstOrDefaultAsync method but the foreignkey table is null. Also does not allow to define Include in FirstOrDefaultAsync method. I will be glad if you help me

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    gterdem created
    Support Team

    Can you give more information about your issue and share some code to show that what you are trying to achieve and what exactly occurs?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    QuickApp created

    I have two tables named QWorkspace and QWorkspaceGroup. And there is a foreignkey link between these two tables. (QWorkSpace (Id) ->QWorkSpaceGroup (QWorkSpaceId)

    I'm pulling a record from the table with the code below.

    QWorkSpace qWorkSpace = await _qWorkSpaceRepository.FirstOrDefaultAsync(e => e.Id == input.QWorkSpaceId);

    When I call the table as qWorkSpace.QWorkspaceGroup, it is null.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you can do it like this;

    await _qWorkSpaceRepository.GetAll().Include(x => x.WorkspaceGroups).FirstOrDefaultAsync()
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    QuickApp created

    Thanks @ismcagdas

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)