Dynamic views in the EF (e.g. pre-filtered data)

I have been working with a DLINQ application since May, and quite possibly the single most frustrating portion of my application is scope limitation. When a user logs into the system, depending on where they are in the application or what they're doing, a query is performed against one of the following scopes:

- public or private data "owned" by the user
- public data owned by anyone in the system (including the user)
- data owned by named groups of users

Is there something I can do in the EF where I can possibly do dynamic views? I was thinking of perhaps:

var allBooks = from book in AllBooks select book;
var myBooks = from book in MyBooks (yet this data came from the same table) select book;
var publicBooks = from book in PublicBooks select book;

or possibly using entity inheritance:

var myBooks = from book in Books where book is MyBook(userId);
^^ would the above work if I instantiate myBook with the userID and have a condition in the EM that dictates that MyBooks are only those books where OwnerID == UserID ?

I would like "MyBooks" to be able to pick up either through context (wishful thinking) or through parameter (e.g. MyBooks(userId)) the Id of the requesting user and return the list of books accordingly.

I am looking to make my queries easy to read, and sometimes I spend so many lines of code getting the scope of the source of the query adjusted that I often lose site of the original point of the query.

[1469 byte] By [KevinHoffman] at [2008-2-15]
# 1
While custom mapping behaviors are not supported in the current entity CTP, we plan on addressing certain scenarios in this release. Making the mapping views dynamic w.r.t. some extended property of the context or a parameter (e.g. "userID") is a possibility.

Thank you for your feedback,

-Colin

ColinMeek at 2007-8-31 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...

Visual Studio Orcas

Site Classified