我想填充AccountNumber不存在的Transaction数据。我需要访问帐户表来获取。我收到以下错误在那里我试图返回的IEnumerable无法将类型'System.Collections.Generic.IEnumerable <AnonymousType#1>'隐式转换为'System.Collections.Generic.List <modelClass>
不能隐式类型转换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;
}
这工作完美。优秀的答案。非常感谢让我走向正确的方向。做到这一点,我也学到了其他一些东西。现在我知道什么是ViewModel。 – shaz 2013-02-12 21:33:52