+6  A: 

This works for me (with different tables of course, but same relationship):

IQuerable<Pet> personPets = (
   from p in db.Person
   where p.ID == somePersonID
   select p
).Single().Pets.AsQueryable();

Although I'd probably write it in some variation of this way:

var personPets = (
    db.Person.Single(t=>t.Id == somePersonId).Pets.AsQueryable()
);
Blorgbeard
Thanks Blorg; that was my original query actually before I started to break it down into a separate collection of Pets. Same exception however, "An explicit conversion exists (are you missing a cast?)" Thanks for the suggestion!
p.campbell
Hmm, what about this?
Blorgbeard
That change has worked!
p.campbell
+1  A: 

I have the following and it works perfectly. Which I setup a simple database with your above mentioned two tables, and generate the dataclass with VS.

var db = new DataClasses1DataContext();
var personPets = from p in db.Persons
                 where p.PersonId == 1
                 select p.Pet;

It looks like to me, your Person is actually the Class instead of the database object (which is by default named by the code generator). Test if the above works for you first, sometimes the debugger may simply give you some freaky reason which is not actually pointing to the real problem.

xandy
+1  A: 
List<Pet> personPets = 
   (from p in Persons
   where p.ID == somePersonID
   select p.Pets).ToList();

Try something like this.

Andrew Siemer
+1  A: 

Look at your query:

    var personPets= from p in Person
    where p.ID == somePersonID
    select p.Pets;

What is happening is that you are returning an IEnumerable (of one element) of IEntitySet<Pet> types (the type: IEnumerable<IEntitySet<Pet>>).

You should get an IEnumerable<Pet> and it will be converted to IQueryable<Pet> by the AsQueryable method:

public IQueryable<Pet> GetPersonPets(int personID)
{
    var person = Person.Single(p=> p.ID == personID);

    return person.Pets.AsQueryable();
}
CMS
A: 

what worked for me,

    var db = new DataClasses1DataContext();
var personPets = from p in db.Persons
                 where p.PersonId == 1
                 select p.Pet;
IQuerable<Pet> pets = (IQuerable<Pet>)personPets;

strangely enough

Hellola