I am trying to find the prefixes of my account names so I can use them in a filter in my UI.
However whenever I execute the following linq statement it always brings back the whole account name and then performs the substring. Instead of writing the sql equivalent.
return this.Accounts(user).Select(x => x.Name.Substring(0, 1)).ToList().Distinct();
this.Accounts is IQueryable so it should not force a callback to the database.
Is there any reason why it would return them all and then substring the resulting names or is there a working alternative?
Edit
private IQueryable<Account> Accounts(User user)
{
var accounts = this.SessionManager.GetActiveSession().Query<Account>().Where(x => x.Company.Id == user.Company.Id);
if (!user.IsAdmin && user.AccountProfiles.Any())
{
accounts = accounts.Where(x => x.AssociatedProfiles.Any(y => y.Users.Any(z => z.Id == user.Id)));
}
return accounts;
}
this.Accounts.this.Accountsis still missing. The behavior you described would be consistent with that property being declared asIEnumerable<Account>.