【发布时间】:2011-08-24 22:06:43
【问题描述】:
我有这个问题:
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
};
这是错误的:
LINQ to Entities does not recognize the method 'System.String GetAccountTypeDescription(System.String)' method, and this method cannot be translated into a store expression.
功能是:
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;
}
如果我不在 LINQ 查询中使用 GetAccountTypeDescription,它可以工作。
请提出解决方案
【问题讨论】:
-
从您的编辑中,我不明白您为什么不简单地将其作为连接包含在较大的 linq 查询中。
-
@Steen:如何修改查询以将此函数用作连接?
标签: c# .net linq entity-framework asp.net-mvc-3