0

I have hotchoc all connected up to EF and a sqlserver db. Here is my query...

query
{
  accounts {
    holdings {
      holdingId
    }
  }
}

If I don't have [UseSelection] on my accounts method, the sql statement pulls all the fields on the accounts table but doesn't do a join to holdings. If I put [UseSelection] on accounts then it correctly selects just the fields I want and joins to holdings to get holdingId. However, it also fires this sql statement...

SELECT [e].[AccountID]\r\nFROM [Accounts] AS [e]\r\nORDER BY [e].[AccountID]

What is this extra sql statement for? Have I done something wrong?

My Account entity...

public class Account : BaseEntity
    {
        public Account()
        {
            AccrualTransactions = new HashSet<AccrualTransaction>();
            Transactions = new HashSet<Transaction>();
            Holdings = new HashSet<Holding>();
        }

        public int AccountId { get; set; }
        public string AccountName { get; set; }
        public string AccountNumber { get; set; }

        public ICollection<Transaction> Transactions { get; set; }
        public ICollection<Holding> Holdings { get; set; }
    }

The table structure is pretty simple. Holdings table has an AccountId. The Account table has a lot of fields but nothing suspicous.

FeeFiFoFum
  • 1,719
  • 1
  • 11
  • 18

1 Answers1

0

Are you using [Parent] attribute in the Resolver method or context.Parent in the resolver Func ?

This will cause the Parent (Account in your case) Id to be fetched.

Other than that the join with holdings will work with or without [UseSelection].

Dharman
  • 30,962
  • 25
  • 85
  • 135
Saad
  • 31
  • 4
  • 3
    This does contain a decent answer. But please try not to dilute it too much with clarification questions, for which you need the commenting privilege. https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead – Yunnosch Sep 07 '20 at 14:00