We have a DataTier. Inside this DataTier are models that represent various tables/fields. These models are also associated with their respective DbContext (We’ll call it OurDbContext).
public class Foo
{
public string Field1 { get; set; }
public string Field2 { get; set; }
}
In a particular project, I want to add a field to Foo that’s not in the table.
public class Bar : Foo
{
public string Field3 { get; set; }
}
I want to create an IQueryable for delayed execution.
IQueryable<Bar> queryable = OurDbContext.Foo.FromSqlRaw(someSQl)
.AsNoTracking()
.Select(x => new Bar()
{
Field1 = x.Field1
Field2 = x.Field2
Field3 = "somedata"
});
When you look at the Intellisense, it says that .Select is returning an IQueryable.
But what I see happening is that the second we create the IQueryable, it’s executing SQL. We want to use an IQueryable with delayed execution, so we can skip/take 100 records at a time through the GUI.
But, with it executing like it is, it iterates over every record in the database before we can skip/take. Which stinks.
What am I missing here?