Print Page | Close Window

How To Examine Filter On Server

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2464
Printed Date: 29-Jul-2026 at 3:08pm


Topic: How To Examine Filter On Server
Posted By: gregweb
Subject: How To Examine Filter On Server
Date Posted: 23-Jan-2011 at 8:53am
I have this on the client:
 
var query = EmailEntityManager.vEmailMessageEntities;
this._vEmailMessages = new EntityQueryPagedCollectionView(
 query,
 this.PageSize,
 this.PageSize,
 true,
 false
 );
var filter = new PredicateDescription(typeof(vEmailMessageEntity), "FolderId"FilterOperator.IsEqualTo, 1785);
Note that it has a filter on it.  In some cases, however, I am going to remove the filter on the client.  
On the server, in the QueryInterceptor, I need to be able to examine the filter, and if it does not 
specify a folderId, I want to add it.  I know how it add it, I just don't know how to examine the query in the Query
interceptor to see if it is there or not.
Thanks,
Greg



Replies:
Posted By: gregweb
Date Posted: 23-Jan-2011 at 10:03am
Also, it seems if there is already a filter, and I try to add another one, it replaces the existing filter:
 
var filter = new PredicateDescription(typeof(EmailFolderEntity), "EmailAccountId"FilterOperator.IsEqualTo, 1);
this.QueryFilters.AddFilter(filter, true);
If I change the parameter to false, I get the following error message:
A filter for type:Jet.Models.EmailFolderEntity already exists within this EntityQueryFilterCollection
Is there a way to keep the existing filter and just add the new one?
Greg


Posted By: sbelini
Date Posted: 25-Jan-2011 at 4:36pm
Hi Greg,
 
To answer your first question, (how to examine filter on server) you can use:
var filter = this.QueryFilters.GetFilterQueryForType(typeof(EmailFolderEntity));
 
to verify if there is a filter already present and examine it. (if no filter present for the given type, filter = null )
 
As for your second question, (is there a way to keep the existing filter and just add the new one?) you can only have one filter per Entity Type. However, you can have a filter with both existing and new criteria:
 
  var existingfilter = this.QueryFilters.GetFilterQueryForType(typeof(Customer));
  var newfilter = new PredicateDescription(typeof(Customer), "CompanyName", FilterOperator.StartsWith, "B");
 
  var combinedfilters = PredicateBuilder.FilterQuery((IEntityQuery<Customer>)existingfilter, newfilter);
  QueryFilters.AddFilter<Customer>((IQueryable<Customer> q) => q = (IQueryable<Customer>)combinedfilters, true);
 
Can you explain your case scenario in detail? Are you indeed in need to add a filter? Or would simply having a where clause sufice?
 
Silvio.


Posted By: gregweb
Date Posted: 25-Jan-2011 at 7:05pm
Hi Silvio,
 
Perhaps I misunderstand the difference between a filter and a where clause.  I thought a filter was a where clause. 
 
This is what i am trying to do:
 
I have this on the client:
 
var query = EmailEntityManager.vEmailMessageEntities.Where(a=> a.FolderId == 254);
this._vEmailMessages = new EntityQueryPagedCollectionView(
 query,
 this.PageSize,
 this.PageSize,
 true,
 false
 );
 
Then, the user selects a different folder.  I need to requery, this time with a where clause on it, such as FolderId = 255;  This happens on the client.
 
Then on the server, I need to enforce security.  I need to add an additional where clause on it to make sure that in addition to FolderId = 255, that  'OwnedBy' == 1.
 
I wanted to do the second part on the server just to make sure no-one was trying to access data that didn't actually belong to them.  Otherwise, if they could manage to send up a folder ID of say 555, it might be someone else's data.
 
Thanks so much,
 
Greg
 


Posted By: sbelini
Date Posted: 31-Jan-2011 at 4:38pm
Hi Greg,
 
A filter acts like a Where clause, but it's more powerful in the sense that every reference to an entity will be filtered. (except .Include's)
 
Based on what you described, my best guess is that you want to 'filter' the current user throughout the lifespan of the session, while the folder can be randomly selected by the user to be viewed.
 
My sugestion is that you create a filter for the current user (no matter what folder she selects, she'll only get data belonging to her). As for folders, you can always re-query them based on the user's selection.
 
Silvio.


Posted By: gregweb
Date Posted: 01-Feb-2011 at 7:27am
Thanks very much, this was very helpful.
 
Greg



Print Page | Close Window