Reputation: 13
Error:
Convert implicitly system.collections.generic.list return data query
My code:
public List<td_encuestas> getEncPreg(int userId)
{
db.Configuration.LazyLoadingEnabled = false;
var encuesta = (from enc in db.td_encuestas
join pre in db.td_preguntas on enc.enc_id equals pre.pre_enc_id
join res in db.td_respuestas on pre.pre_enc_id equals res.res_id
where enc.enc_activo == "true"
&& pre.pre_activo == "true"
&& enc.enc_usr_id_registro == userId
orderby enc.enc_descripcion
select new
{
enc,
pre,
res
}).ToList();
return encuesta;
}
Return collection and relationship
Upvotes: 1
Views: 2230
Reputation: 364
The Linq procedure that you are using does not return a List of that type/object, you should use a dynamic method, which returns something without knowing what it is, here's the code:
public dynamic List<td_encuestas> getEncPreg(int userId)
{
db.Configuration.LazyLoadingEnabled = false;
var encuesta = (from enc in db.td_encuestas
join pre in db.td_preguntas
on enc.enc_id equals pre.pre_enc_id
join res in db.td_respuestas
on pre.pre_enc_id equals res.res_id
where enc.enc_activo == "true"
&& pre.pre_activo == "true"
&& enc.enc_usr_id_registro == userId
orderby enc.enc_descripcion
select new
{
enc,
pre,
res
}).ToList();
return encuesta;
}
And to use it:
var obj = getEncPreg(someId);
Upvotes: 1