我正在尝试填充 AccountNumber 不存在的交易数据。我需要访问 Account 表来获得它。我在尝试返回 IEnumerable 时收到以下错误
无法将类型隐式转换System.Collections.Generic.IEnumerable<AnonymousType#1>
为System.Collections.Generic.List<ProjectModel.Transaction>
错误显示在.ToList(); 部分代码。我究竟做错了什么?
代码是:
public static IEnumerable<Transaction>GetAllTransactions()
{
List<Transaction> allTransactions = new List<Transaction>();
using (var context = new CostReportEntities())
{
allTransactions = (from t in context.Transactions
join acc in context.Accounts on t.AccountID equals acc.AccountID
where t.AccountID == acc.AccountID
select new
{
acc.AccountNumber,
t.LocalAmount
}).ToList();
}
return allTransactions;
}