You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Hi,
I'm having some trouble with using the inlinecount with a child navigation property using projections.
Here are the classes:
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
The text was updated successfully, but these errors were encountered: