1

I want to return my result as array list. My code looks like this:

public Person Get(string doctorCode)
{
     using (PharmaOCEAN_LTEntities entities = new PharmaOCEAN_LTEntities())                   
     {
         return entities.Person.FirstOrDefault(e => e.DoctorLicenseNumber == doctorCode);
     }
}

Some guy informed me that selected (all) result will be an array, so I tried this way, but im getting an error with select statement:

public IList<Person> Get(string doctorCode)
{
    using (PharmaOCEAN_LTEntities entities = new PharmaOCEAN_LTEntities())                   
    {
        return entities.Person.Select<Person>(e => e.DoctorLicenseNumber == doctorCode);
    }
}

any opinions?

2 Answers 2

1

Yeah sure you can! As a array:

public Person[] Get(string doctorCode)
{
    using (PharmaOCEAN_LTEntities entities = new PharmaOCEAN_LTEntities())                   
    {
        return entities.Person.Where(e => e.DoctorLicenseNumber == doctorCode).ToArray();
    }
}

As a list:

public IEnumerable<Person> Get(string doctorCode)
{
    using (PharmaOCEAN_LTEntities entities = new PharmaOCEAN_LTEntities())                   
    {
        return entities.Person.Where(e => e.DoctorLicenseNumber == doctorCode).ToList();
    }
}

not sure if it compiles, but you get the message :)

Sign up to request clarification or add additional context in comments.

Comments

0

Can you provide info error that you get?

Don't you have to add ToList() at the end of select statement?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.