Entity table to string[]

I'm trying to return a list of questions from a database that I define as a list and try to send back to a page as an array. The Error I am getting is Cannot implicitly convert type 'Model.tblQuestion[]' to 'string[]'. What am I doing wrong?

 public string[] GetQuestions(string prefix)
    {
        List<string> customers = new List<string>();
        List<tblQuestion> p4 = new List<tblQuestion>();
        using (HRPWREntities db = new HRPWREntities())
        {
           p4 = (from x in db.tblQuestions where prefix.Contains(x.Question) orderby x.AskID select new tblQuestion { Question = x.Question, AskID = x.AskID });
       
        }
           
            return p4.ToArray();
       
    }
NickMalloyAsked:
Who is Participating?
 
Daniel Van Der WerkenConnect With a Mentor Independent ConsultantCommented:
Somewhere along the line you need to "strip" out the string portion of the tblQuestion object and addi tto the customer's list. Something like this:

using( HRPWREntities db - new HRPWREntities())
{
   p4 = <stuff>;
   customers.Add( p4.Question);
}
return customers.ToArray();

Open in new window

0
 
Obadiah ChristopherCommented:
return p4.ToArray();

This should be throwing the error.

I guess you might have to use something like

public List<tblQuestion> GetQuestions(string prefix)
{
        return p4;
}
0
 
NickMalloyAuthor Commented:
This doesn't seem to be valid as it doesn't allow me to select the column names.

customers.Add( p4.Question);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.