Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
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


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?

  • 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.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you can do it like this;

    await _qWorkSpaceRepository.GetAll().Include(x => x.WorkspaceGroups).FirstOrDefaultAsync()
    
  • User Avatar
    0
    QuickApp created

    Thanks @ismcagdas