I have this query:
var accounts =
from account in context.Accounts
from owner in account.AccountOwners
join business in context.Businesses
on account.CreditRegistryId
equals business.RegistryId
join astatus in context.AccountStatuses
on account.AccountStatusId
equals astatus.AccountStatusId
join LS in context.LegalStatuses
on account.LegalStatusId
equals LS.LegalStatusId
where !excludeTypes.Contains(account.AccountType)
select new AccountsReport
{
AccountTypeDescription = GetAccountTypeDescription(account.AccountType),
AccountNumber = 1,
AccountStatus = "aasd",
CreditorAddress = "address",
CreditorCity = "my city",
CreditorName = "creditor name",
CreditorState = "my state",
LegalStatus = "my status",
RegistryId = 121323
};
which is giving error:
LINQ to Entities does not recognize the method 'System.String GetAccountTypeDescription(System.String)' method, and this method cannot be translated into a store expression.
Function is :
public string GetAccountTypeDescription(string accountType)
{
var result = context.AccountTypes.Where(x => x.AccountTypeCode == accountType).Select(x => x.Abbreviation).SingleOrDefault();
if (string.IsNullOrEmpty(result))
{
result = accountType;
}
return result;
}
If I don't use GetAccountTypeDescription in LINQ query, It works.
Please suggest solution