Sto lavorando con .NET4.5 e VS2013, ho questa query che ottiene il risultato dynamic
da db.Impossibile utilizzare un'espressione lambda come argomento per un'operazione inviata dinamicamente senza prima inoltrarla a un delegato o ad un tipo di albero di espressioni
dynamic topAgents = this._dataContext.Sql(
"select t.create_user_id as \"User\", sum(t.netamount) as \"Amount\" from transactiondetail t where t.update_date > sysdate -7 group by t.create_user_id")
.QueryMany<dynamic>();
seguito istruzione ha esito negativo con l'errore di compilazione Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
senza nemmeno che mi permette di eseguirlo
mentre questo con foreach
funziona bene.
var data = new List<List<object>>();
foreach (dynamic agent in topAgents)
{
data.Add(new List<object>
{
agent.User != null ? string.Format("{0}", agent.User).Replace("CORPNTGB\\", "") : null,
agent.Amount
});
}
Ai miei occhi dopo che ho topAgents.ToList()
che potrebbe essere interpretato come equivalente, è perché ho esplicitamente che var data = new List<List<object>>();
che seconda dichiarazione è consentito dal compilatore?
Perché il compilatore non consente LINQ selezionare, ma consente per ciascuno?
I 'topAgents' devono essere' dynamic'? Funziona se usi 'var' invece? – DavidG