Does anyone have any idea how to limit result set of EntityFramework permanently? I'm speaking about something like this Conditional Mapping. This is exactly what I want to achieve with one exception: I want to do this programmatically. That's because condition value will be passed to EF only on context creation. Beside I don't want this column to disappear from mapping.
I know how to achieve this with EF2.0 and reflection. I was using CreateQuery()
method to generate my own ObjectQuery
. CreateQuery()
allows to inject my own ESQL query with additional condition e.g. WHERE TABLE.ClientID == value
.
Problem with EF40 is that there is no more ObjectQuery
but only ObjectSet
and CreateQuery()
is not used. I have no idea how to inject my own ESQL query.
The reason why I want to limit result sets is that I want to separate clients data from each other. This separation should be done automatically inside context so that programmers will not have to add condition .Where(x => x.ClientID == 5)
to each individual query.
Maybe my approach is completely bad — but I don't know any alternative.