copy RelationPredicateBucket

Posts   
 
    
El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 09-Nov-2006 09:13:15   

I'm writing a ASP.Net search page. The page contains serveral custom controls that make up the search query. The RelationPredicateBucket is ideal for this situation as I can share an instance of this object between all controls. Each control can add it's relation and predicates to it and when the user hits "search" i can use the object to get the data from the database. However, I encountered a little problem. Some of the search controls on the page need the filter aswell, to get some data. And they need to add some relations/predicates to do so. These relations/predicates are of no interest of other search controls, so I thought to copy the RelationPredicateBucket object to use the RelationPredicateBucket internally.

I couldn't find a copy method for the RelationPredicateBucket, so I tried to copy it manualy like:


            IRelationPredicateBucket filter = searchObject.GetFilter();
            IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
            subFilter.Relations.AddRange(filter.Relations);

This code threw an exception because the AddRange methode would only accept a ICollection as argument. So I came up with this:


            IRelationPredicateBucket filter = searchObject.GetFilter();
            IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
            for (int i = 0; i < filter.Relations.Count; i++) {
                subFilter.Relations.Add(filter.Relations[i]);
            }

It works, but I was wondering if there is any other (more elegant) appoach to do this.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 09-Nov-2006 10:22:01   

How about the 'Clone' method? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 13-Nov-2006 21:14:55   

Any chance of getting a Clone() for EntityRelation? smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 13-Nov-2006 22:42:12   

mikeg22 wrote:

Any chance of getting a Clone() for EntityRelation? smile

It's best to call the property again to get a new instance. Though that requires the knowledge which property to call to get the new instance, and that's currently not possible. So I'm thinking of adding that name (also for projections of a hierarchy) to the next version (2.1), but it's currently not available.

Though why do you need a hard clone? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 14-Nov-2006 03:29:21   

Otis wrote:

mikeg22 wrote:

Any chance of getting a Clone() for EntityRelation? smile

It's best to call the property again to get a new instance. Though that requires the knowledge which property to call to get the new instance, and that's currently not possible. So I'm thinking of adding that name (also for projections of a hierarchy) to the next version (2.1), but it's currently not available.

Though why do you need a hard clone? simple_smile

Our security objects on the server intercept PrefetchPaths and "fix them up" so that they include security-related filtering. This is so any PrefetchPath can come into the server in a FetchEntity call, and security-filtered data is returned. Part of this fixing up is copying EntityRelations and making changes to them, possibly changing aliases in some cases.

The reason we can't just call the property again is that the security objects deal with all entities and prefetch paths generically. I suppose we could use reflection but that would involve guessing at the relation property names that hang off the entities.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 14-Nov-2006 10:24:36   

Yes good point. You could do this in a routine of your own for the time being, if I haven't overlooked something.

You could create a new EntityRelation and use the Clone() method on the EntityField2 object to create a clone of these. The rest is simply moving over information you obtain from the original EntityRelation.

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 14-Nov-2006 15:33:49   

Otis wrote:

Yes good point. You could do this in a routine of your own for the time being, if I haven't overlooked something.

You could create a new EntityRelation and use the Clone() method on the EntityField2 object to create a clone of these. The rest is simply moving over information you obtain from the original EntityRelation.

We have our own "CopyEntityRelation" method now. Clone would be a little more intuitive, but its not a real problem. If you do get around to it, could you put it in 1.2005.1? simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 14-Nov-2006 15:39:33   

No, additional stuff won't be added to 1.0.2005.1, that api and all versions before it are frozen as a new version has been released, we only fix issues in that code if they arise.

Frans Bouma | Lead developer LLBLGen Pro
cerbas
User
Posts: 2
Joined: 28-Nov-2006
# Posted on: 22-Jan-2007 14:31:38   

El wrote:

I'm writing a ASP.Net search page. The page contains serveral custom controls that make up the search query. The RelationPredicateBucket is ideal for this situation as I can share an instance of this object between all controls. Each control can add it's relation and predicates to it and when the user hits "search" i can use the object to get the data from the database. However, I encountered a little problem. Some of the search controls on the page need the filter aswell, to get some data. And they need to add some relations/predicates to do so. These relations/predicates are of no interest of other search controls, so I thought to copy the RelationPredicateBucket object to use the RelationPredicateBucket internally.

I couldn't find a copy method for the RelationPredicateBucket, so I tried to copy it manualy like:


            IRelationPredicateBucket filter = searchObject.GetFilter();
            IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
            subFilter.Relations.AddRange(filter.Relations);

This code threw an exception because the AddRange methode would only accept a ICollection as argument. So I came up with this:


            IRelationPredicateBucket filter = searchObject.GetFilter();
            IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
            for (int i = 0; i < filter.Relations.Count; i++) {
                subFilter.Relations.Add(filter.Relations[i]);
            }

It works, but I was wondering if there is any other (more elegant) appoach to do this.

I agrree that this is working when you do not have relation aliases. Sample which is not wroking for me: IRelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.Relations.Add ( PrinterEntity.Relations.PrinterTrayEntityUsingPrinterID ); bucket.Relations.Add ( FormEntity.Relations.PrinterEntityUsingDefaultPrinterID, "DefaultPrinter", JoinHint.Left ); subFilter.Relations.Add(filter.Relations[i]);

if I write: IRelationPredicateBucket clonedFilter = new RelationPredicateBucket(); for (int i = 0; i < bucket .Relations.Count; i++) { clonedFilter.Relations.Add(bucket .Relations[i]); }

alias "DefaultPrinter" dissapiers.. also from original relation. I am doing something wrong? simple_smile

regards

cerbas
User
Posts: 2
Joined: 28-Nov-2006
# Posted on: 22-Jan-2007 15:00:46   

Uh.. sorry.. after some investigation I found workaround for this, which I think is more correct way:

ArrayList relationList = new ArrayList(); for ( int i = 0; bucket.Relations.Count; i++ ) { relationList.Add(bucket.Relations[i]); }

IRelationPredicateBucket clonedBucket = new RelationPredicateBucket(); clonedBucket.Relations.AddRange(relationList);

simple_smile

thanks.. so when we can expect clone method for this? simple_smile currently we are using version 1.0.2005.1.

regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 22-Jan-2007 16:12:38   

Upgrade to v2.0, and it's there simple_smile

Frans Bouma | Lead developer LLBLGen Pro