Cannot implicitly convert type IEnumerable to IQueryable

前端 未结 5 2035
一个人的身影
一个人的身影 2021-02-05 07:46

Obfuscated Scenario: A person has zero, one or many pets.

Using Linq to Sql, the need is to get an IQueryable list of pets for the given pe

5条回答
  •  醉梦人生
    2021-02-05 08:21

    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.

提交回复
热议问题