Riddhi Valecha

Riddhi Valecha

  • 443
  • 3.3k
  • 413k

EntityFramework- Error in converting to to 'System.Collections.Generic

Dec 10 2020 9:20 AM

Hello Team,

My Code is -

namespace Models
{
public class getChildQuestions
{
public int qid { get; set; }
public string qname { get; set; }
}
public class GetCPQuestionMasterModel
{
public Int32 QID_Get { get; set; }

public List<getChildQuestions> Child_Question_Get { get; set; }
public Int32 Active_Get { get; set; }
}
}
-----------------------------
namespace DAL
{
public static List<getChildQuestions> SubQuestions(Int32 QuestionID)
{

CPContext Context = new CPContext();
var SubQuestions = (from CB in Context .Question_Master
where CB.FKQID == QuestionID
select new getChildQuestions
{
qid = CB.QID,
qname = CB.Question
});

return SubQuestions.ToList();
}
---------
public List<GetCPModel> GetQuestionMaster(GetCPModel _Req)
{
CPContext Context = new CPContext ();
List<GetCPModel> _resReponseModel = null;
Int32 QuestionMasterCount = Context.Question_Master.Count();
if (QuestionMasterCount > 0)
{
_resReponseModel = (from p in Context.Question_Master

select new GetCPModel
{
QID_Get = p.QID,
Child_Question_Get = SubQuestions(p.FKQID),
Active_Get = p.Active,

}).ToList();
}
return _resReponseModel ;

}
}
-------------
On Line "Child_Question_Get = SubQuestions(p.FKQID), ", I am 
 I am getting an error -"Error in converting "how are you" to 'System.Collections.Generic.List`. 
 
Please guide .. ITs really urgent. 

Answers (12)