I'm wondering how one would go about streaming data from SQL server using EF6.
Assume having these classes
- PersonRepository
- EFPerson (EF model)
- DomainPerson (Domain model)
- PersonUsingClass
Assume that PersonUsingClass depends on getting a bunch of DomainPersons. Assume that business rules dictate that EFPersons aren't allowed to leave the PersonRepository.
Normally I'd have a repository method looking like this:
public IEnumerable<DomainPerson> GetPeople()
{
using (var db = new efContext())
{
IQueryable efPeople = db.Person.Where(someCriteria);
foreach (var person in efPeople)
{
yield return person.ToDomainPerson();
}
}
}
With the code I have here, everything would be loaded into memory upon doing the foreach. I could achieve the streaming by returning the IQueryable to the PersonUsingClass, but that exposes the EF models to that class, which is an unwanted scenario.
Is it really impossible to hide away the EF models while streaming data at the same time? Or is there something I don't know?