• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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();
       
    }
0
NickMalloy
Asked:
NickMalloy
1 Solution
 
informaniacCommented:
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
 
Daniel Van Der WerkenIndependent 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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now