New Posts New Posts RSS Feed: Modifying query results in EntityServerQueryInterceptor
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Modifying query results in EntityServerQueryInterceptor

 Post Reply Post Reply
Author
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Topic: Modifying query results in EntityServerQueryInterceptor
    Posted: 03-Mar-2011 at 11:10am
We have some cases where we'd like to improve performance.  To achieve this what I'd like to do is add a couple commonly queried data to the Entity and flag them as [DataMember].

Using a Northwind analogy, pretend there's no FK between Orders and Customers, or Customers is in a separate database and consider the queries:

var order = Orders.First(o => o.OrderID == 10248)
Customers.Where(c => c.CustomerId == order.CustomerId)

We could add a CustomerName property to the Order entity partial class to avoid the second query, if it could be updated in the EntityServerQueryInterceptor.

    protected override bool ExecuteQuery()
    {
      var result = base.ExecuteQuery();
      if (result)
      {
        //Get QueryResults
        //find all Orders being returned
        //Query all Customers for Orders.CustomerId
        //Update the Order.CustomerName on each Order for the matching Customer
      }
      return result;
    }

Am I looking in the right place to do this?  Any examples of how to do this?

Thanks!


Edited by mikewishart - 13-Mar-2011 at 10:07pm
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 03-Mar-2011 at 12:31pm
I think perhaps a better approach would be to look at doing it from the edmx.

This link may help: http://msdn.microsoft.com/en-us/library/cc716698.aspx




Edited by smi-mark - 03-Mar-2011 at 12:32pm
Back to Top
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Posted: 03-Mar-2011 at 12:39pm
Thanks smi-mark, that's an interesting idea.  It doesn't help with the entities in two dbs.  This also seems to only work if the entities share a common key (such as sub-typing).
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 03-Mar-2011 at 3:57pm
Using Projection may be a better approach:

http://drc.ideablade.com/xwiki/bin/view/Documentation/CookbookSimpleProjection


Edited by smi-mark - 03-Mar-2011 at 3:59pm
Back to Top
mikewishart View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Feb-2010
Location: Reno, NV
Posts: 49
Post Options Post Options   Quote mikewishart Quote  Post ReplyReply Direct Link To This Post Posted: 13-Mar-2011 at 10:06pm
Following up.  I found what I was looking for in the 6.0.3 release notes.

Added QueriedEntities collection to EntityServerQueryInterceptor. [1374]

Now you can examine queried entities on the server before they are sent to the client. You could record what was queried for audit purposes (“What returns has a tax preparer tried to view?”). You can write fine-grained authorization logic to prevent transmission to client of forbidden entities … in case they slip past a protective query filter you added before the query was processed.

You cannot add or remove entities to the collection (yet). You can modify the entities (e.g., obscure the Social Security Number) before they continue on their way to the client. But be careful, especially if you expect the user to be able to update these entities and save them later!

This worked great!  I hope to see adding/removing entities from the result set sometime in the near future.  This would be helpful as well.

PS, in my earlier post I mistakenly wrote [DataContract] rather than [DataMember].  This has been fixed.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down