LinqToQuerystring icon indicating copy to clipboard operation
LinqToQuerystring copied to clipboard

Issue with Inlinecount with navigation properties

Open maganuk opened this issue 10 years ago • 0 comments

Hi,

I'm having some trouble with using the inlinecount with a child navigation property using projections.

Here are the classes:

public class Person
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public ICollection<Address> Addresses { get; set; }
}

public class Address
{
    public int ID { get; set; }
    public string FirstLine { get; set; }
    public string SecondLine { get; set; }
}

And here is the relevant code:

_unitOfWork.PersonRepository.GetDbSet() .Select(p => new PersonDTO { ID = p.ID, FirstName = p.FirstName, LastName = p.LastName, Address = p.Address.Select(x => new AddressDTO { Id = x.ID, FirstLine = x.FirstLine, SecondLine = x.SecondLine}).ToList() }) .LinqToQuerystring(typeof(PersonDTO), query));

Everything works fine (including filtering, sorting) except when I introduce the Inlinecount=allpages querystring. The inner exception that i'm getting is:

"There is already an open DataReader associated with this Command which must be closed first."

If I do a ToList().AsQueryable() between the .linqToQueryString and the Select statement it works fine but that means that first the entire dataset is queried and then the filtering happens on the returned dataset. I would like to avoid that as we're dealing with a large dataset. Is there any way I can get the required data with a single call to the API?

Thanks Best Regards

Vishal

maganuk avatar Nov 17 '15 17:11 maganuk