I'm developing an OData service which exposes a model created with Entity Framework 6. These entities are read only and are quite large to load. (Several gigabytes)
To accomplish this I'm using Microsoft.OData.EntityFrameworkProvider, (I'm not currently using WebAPI) This is mostly working fine, however I have a new requirement that needs to expose an entity which is actually a union of multiple other entities for convenience to our EndUser / customer.
EF Context Snippet
...
public DbSet<Foo> FooRecs { get; set; }
public DbSet<Bar> BarRecs { get; set; }
public IQueryable<FooBarRec> FooBarRecs
{
get
{
return FooRecs.Select(f => new FooBarRec() { Id = f.Id, Description = f.Description })
.Union(
BarRecs.Select(b => new FooBarRec() { Id = b.Id, Description = b.Description })
);
}
}
...
I'm unable to expose this IQueryable property through odata as it appears that the EntityFrameworkProvider only exposes DbSets and not any IQueryable object, which makes sense.
My question is, what is the best approach to accomplish this with OData?
I'd like to avoid loading duplicate data into a third intermediate table as the data can be large, and the time to load that data which is done nightly. It appears that QueryInterceptor only lets you subfilter data which is already queried so that doesn't seem to work.
I tried doing crazy things like extend DbSet and make my own DbViewSet which takes both sets in it's constructor, but couldn't find a way to close the loop.
What is the best way to accomplish something analogous to a view with OData and EF6?
Thanks!