3
votes

I'm running the following query which contains a child => parent relationship between Case and Account - and contains the Account.Name in the SELECT:

string query = "SELECT Case.CaseNumber,Case.Account.Name,Case.Status FROM Case WHERE Status != 'Closed' AND OwnerId IN (SELECT Id FROM User WHERE Email = '" + userEmail + "') ORDER BY Account.Name";
var results = await client.QueryAsync<CaseWorkload>(query);

The CaseWorkload class is defined as:

public class CaseWorkload
{
    public string CaseNumber { get; set; }
    public string Status { get; set; }
    public string AccountName { get; set; }
}

I am unable to retrieve the AccountName information as the returned SQL shows Account.Name and I couldn't find a way in SOQL to alias a column. How should the class be created considering the given query?

1

1 Answers

5
votes

You need to do the following to get the Account Name - then of course you can map the Account Name to a property in CaseWorkload if desired:

public class CaseAccount
{
    public string Name { get; set; }
}

public class CaseWorkload
{
    public string CaseNumber { get; set; }
    public string Status { get; set; }
    public CaseAccount Account { get; set; }
}