New Posts New Posts RSS Feed: QueryFilters
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

QueryFilters

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

Joined: 23-Jun-2010
Posts: 21
Post Options Post Options   Quote gkneo Quote  Post ReplyReply Direct Link To This Post Topic: QueryFilters
    Posted: 10-Nov-2010 at 1:44am
Hi.

I have like 50 entities  in my model and the 30 of them have the same property : Id_Parent (Just the same name and type, they are not inheriting from a base entity)

All queries must have this property included in the Where clause.  In order to avoid developers from forgetting to include this property in their queries, I am using a custom EntityServerQueryInterceptor. So, for my 30 entities  I have in my interceptor: 
int idParent= GetIdParent();
this.QueryFilters.AddFilter<Entity1>(q => q.Where(i => i.Id_Parent== idParent));
this.QueryFilters.AddFilter<Entity2>(q => q.Where(i => i.Id_Parent== idParent));
...
this.QueryFilters.AddFilter<Entity30>(q => q.Where(i => i.Id_Parent== idParent));
Is this the best approach?   Now, I need to add another 20 entities to my model, and all of them have this property.  Do I have to another 20 filters?  What about the performance?




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: 10-Nov-2010 at 3:12pm
Hi gkneo,
 
To avoid adding each filter manually, you can use the metadataStore to get a collection of all entity types and add filters for each one that has idParent.
 
As for performance, there won't be a negative impact performant because the EntityQueryFilterCollection (i.e. QueryFilters) is implemented as a hash map. (and therefore the number of filters in the collection does not significantly affect performance)
 
Regards,
   Silvio.
Back to Top
gkneo View Drop Down
Newbie
Newbie
Avatar

Joined: 23-Jun-2010
Posts: 21
Post Options Post Options   Quote gkneo Quote  Post ReplyReply Direct Link To This Post Posted: 11-Nov-2010 at 12:04am
Is it possible to get only the entity types involved in the query?  

I have tried your suggestion but I don't know how to use method AddFilter dynamically as it expects a concrete Entity  type as T.


            var list = this.EntityManager.MetadataStore.GetEntityTypes();

            foreach (var item in list)
            {
                var meta= IdeaBlade.EntityModel.EntityMetadataStore.Instance.GetEntityMetadata(item);
                var dp = meta.DataProperties["Id_Parent"];
                if (dp != null)
                    this.QueryFilters.AddFilter ?????????????

            }





Guillermo
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: 11-Nov-2010 at 11:51am
Hi Guillermo,
 
try
public void AddFilter(IdeaBlade.Linq.IPredicateDescription pd, bool canReplaceIfAlreadyExists = false);
instead:
 
  var list = this.EntityManager.MetadataStore.GetEntityTypes();
  foreach (var item in list) {
    var meta = IdeaBlade.EntityModel.EntityMetadataStore.Instance.GetEntityMetadata(item);
    var dp = meta.DataProperties["Id_Parent"];
    if (dp != null) {
      //this.QueryFilters.AddFilter ?????????????
      var filter = new PredicateDescription(item, "Id_Parent", FilterOperator.IsEqualTo, 1);
      this.QueryFilters.AddFilter(filter);
    }
  }
 
Regards,
   Silvio.
Back to Top
gkneo View Drop Down
Newbie
Newbie
Avatar

Joined: 23-Jun-2010
Posts: 21
Post Options Post Options   Quote gkneo Quote  Post ReplyReply Direct Link To This Post Posted: 15-Nov-2010 at 1:16am
Hi, Silvio.

I cannot find the method:
public void AddFilter(IdeaBlade.Linq.IPredicateDescription pd, bool canReplaceIfAlreadyExists = false);

The only available method is :
public void AddFilter<T>(Func<IQueryable<T>, IQueryable<T>> transformFunc) where T : class;

I am using Devforce 2010 6.0.6
Regards,

Guillermo


Edited by gkneo - 15-Nov-2010 at 1:18am
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: 15-Nov-2010 at 9:06am
Hi Guillermo,
 
I apologize for the mix-up.
 
The overload for AddFilter I suggested will be available with the release of DevForce2010 6.0.7.
 
   sbelini.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down