Sto tentando di compilare i dati di transazione in cui AccountNumber non esiste. Devo accedere alla tabella Account per ottenerlo. Sto ottenendo il seguente errore in cui sto cercando di tornare IEnumerableImpossibile convertire implicitamente il tipo 'System.Collections.Generic.IEnumerable <AnonymousType # 1>' a 'System.Collections.Generic.List <modelClass>
Impossibile convertire implicitamente il tipo System.Collections.Generic.IEnumerable<AnonymousType#1>
a System.Collections.Generic.List<ProjectModel.Transaction>
L'errore viene visualizzato sulla parte superiore del ToList(); parte del codice. Che cosa sto facendo di sbagliato?
il codice è:
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;
}
Questo ha funzionato perfettamente. Ottima risposta Grazie mille per avermi messo in direction.Doing proprio in questo che ho imparato poche altre cose. Ora so di cosa tratta ViewModel. – shaz