New Posts New Posts RSS Feed: Filter EntityRelationQuery?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Filter EntityRelationQuery?

 Post Reply Post Reply
Author
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post Topic: Filter EntityRelationQuery?
    Posted: 22-Nov-2010 at 5:16am
Hi

I would like to add filters on my relationship properties. I'm able to intercept the query on the Querying event but it seems I cannot add a filter to the query itself since the Filter() method only works on EntityQuery and not EntityRelationQuery. Is there another way to filter relationship results?

I'm trying to do this since the user logs into a certain application context where he should only be able to see certain records which are linked to that context.




Edited by tersiusk - 22-Nov-2010 at 5:17am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 22-Nov-2010 at 2:55pm
Hi tersiusk,
 
You can trigger the filters by using Select().
In the example below (based on NorthwindIB) both filters for Employees and Orders will fire:
 
var employeesQuery = mgr.Employees
  .Select(eo => new { employees = eo, orders = eo.Orders.Where(o => true
) })
  .ToList()
  .Select(eo => eo.employees)
  .ToList();
Regards,
   sbelini.
 


Edited by sbelini - 22-Nov-2010 at 2:56pm
Back to Top
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post Posted: 22-Nov-2010 at 11:46pm
Thanks for the reply. I'm not exactly sure that is what I was referring to.

Here is a quick code sample of what I was trying to do.  This does not seem to be working. I was looking for a way to filter the default generated relation properties but it looks like it's not possible? 

static void em_Querying(object sender, EntityQueryingEventArgs e)
        {
            if (InterceptQueries)
            {
                IEntityQuery newQuery = null;

                if (e.Query.QueryableType == typeof (Application) && e.Query is EntityRelationQuery)
                {
newQuery = currentQuery.Filter((IQueryable<Application> q) => q.
                 Where(a => a.ApplicationID == User.CurrentUser.applicationID));
                }
e.Query = newQuery ?? e.Query;
}
}
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 23-Nov-2010 at 4:52pm
Hi tersiusk,
 
Sorry for the mixup.
 
At the moment it's not possible to use .Filter in this scenario.
 
We have a feature request to implement a method to convert an EntityRelationQuery to an EntityQuery which would make possible the use of Filter(). We plan that feature in one of the near coming releases.
 
Kind regards,
sbelini
 
Back to Top
papuashu View Drop Down
Newbie
Newbie
Avatar

Joined: 25-Sep-2013
Posts: 1
Post Options Post Options   Quote papuashu Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2013 at 5:22am
Has ever been implemented the feature of converting EntityRelationQuery to EntityQuery?
In my case, I need to add Include to an EntityRelationQuery...
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2013 at 6:30pm
Sorry, this feature has not been implemented.   Supporting an Include on the converted EntityRelationQuery would also probably lead to other issues when DevForce merges these results into cache.  For now, for these situations when you need the Include, your best alternative is to avoid lazy loading and explicitly write an EntityQuery.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down