c# - Cannot initialize TimeSpan with a collection initializer in linq query ¿Syntax error? -


i build viewmodel linq query entities , following foreach:

_result.foreach(t => t.horarioiniafsp = (from u in model.asistenciacurso                                           join t in model.parametros                                           on u.idcurso equals t.valornumerico                                           u.userid.equals(t.userid)                                           && t.nombreparametro == "modulo1"                                           select new timespan                                           {                                           u.horarioinicio                                           }).tolist()); 

however can't rid of error: "cannot initialize system.timespan collection initalizer because not implement ienumerable.

what wrong? suspect matter of syntax can't figure out, formerly did this:

_result.foreach(t => t.horariofinafsp = model.asistenciacurso.where(u => u.userid.equals(t.userid)).select(x => x.horariofin).tolist()); 

which ok because i'm using linq select, tried join lambdas this:

_result.foreach(t => t.horarioiniafsp.addrange(model.asistenciacurso.where(u => u.userid.equals(t.userid)).join(model.parametros, id => id.idcurso, num => num.valornumerico, (id, num) => new timespan { id.horarioinicio }))); 

but triggers same error not being able initialize collection. don't have time google that's why i'm asking question. appreciated. in advance.

(i know solution has been found; posting answer because nobody else has bothered so)

like error says, can't initialize timespan collection initializer.

timespan has four different constructors can choose when creating new one, if have timespan, use that:

from u in model.asistenciacurso join t in model.parametros on u.idcurso equals t.valornumerico u.userid.equals(t.userid) && t.nombreparametro == "modulo1" select u.horarioinicio 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -