Entity table to string[]

Posted on 2012-09-17
Last Modified: 2012-09-17
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();
Question by:NickMalloy
    LVL 20

    Expert Comment

    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;
    LVL 19

    Accepted Solution

    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


    Author Comment

    This doesn't seem to be valid as it doesn't allow me to select the column names.

    customers.Add( p4.Question);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now