LLBL Modify Field in Predicate/Dynamic Bucket Creation

Posts   
 
    
Suchong
User
Posts: 3
Joined: 02-Aug-2019
# Posted on: 02-Aug-2019 17:43:29   

Hi all,

Using llbl 5.5, SQLServer2017 I am trying to use a single bucket to fetch 4 different type of entity, let me explain :

I have a viewEntity(GlTransactionEntity) which is based on 4 children entity (IC,JC,AR and APTransaction), doing a GetEntities on the view entity is too slow because of the way we made our database, so instead i need to fetch all the entities by fetching the 4 children entity one after the other with the same filter and then make the view entity based on them.

The problem is that I want to do it so that the next person using my fetch method won't have to make 4 different RelationPredicateBucket.

Is there any way i can construct my Bucket using, let say ,GLTransactionFields.Id and then change the instance of GLTransactionFields.Id to ICTransactionFields.Id before fetching?

Or maybe i can use a Custom Relation and when using fetch entity on GLTransaction the query knows to fetch the Ic,Jc,Ar,Ap based on the filter instead of the Gl directly


CustomRelation.AddEntityFieldPair(EntityFieldFactory.Create(GlTransactionFieldIndex.Id),
                                              EntityFieldFactory.Create(IcTransactionFieldIndex.Id));
            CustomRelation.AddEntityFieldPair(EntityFieldFactory.Create(GlTransactionFieldIndex.Id),
                                              EntityFieldFactory.Create(JcTransactionFieldIndex.Id));
            CustomRelation.AddEntityFieldPair(EntityFieldFactory.Create(GlTransactionFieldIndex.Id),
                                              EntityFieldFactory.Create(ApTransactionFieldIndex.Id));
            CustomRelation.AddEntityFieldPair(EntityFieldFactory.Create(GlTransactionFieldIndex.Id),
                                              EntityFieldFactory.Create(ArTransactionFieldIndex.Id));


and instead of doing :


var Bucket = new PredicateExpression(IcTransactionFields.DetailSourceTypeCode == "REC");
IcManager.Fetch(Bucket)
Bucket = new PredicateExpression(JcTransactionFields.DetailSourceTypeCode == "REC");
JcManager.Fetch(Bucket)
Bucket = new PredicateExpression(ArTransactionFields.DetailSourceTypeCode == "REC");
ArManager.Fetch(Bucket)
Bucket = new PredicateExpression(ApTransactionFields.DetailSourceTypeCode == "REC");
ApManager.Fetch(Bucket)


I could do :


var Bucket = new PredicateExpression(GENERICFIELD.DetailSourceTypeCode == "REC");
IcManager.Fetch(Bucket);
JcManager.Fetch(Bucket);
ArManager.Fetch(Bucket);
ApManager.Fetch(Bucket)

)

or something of the sort.

The last solution i thought of would be to make a field that changes based on the entity that i want to fetch at runtime but i doubt that is possible.

Thank you for your help

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 03-Aug-2019 09:56:16   

I have a bit of a hard time understand what you're trying to do. You have a view GlTransaction and 4 subtypes and fetching all GlTransaction instances was too slow? However what you're trying to accomplish instead is unclear to me, as one way or the other: the joins have to happen (if that's what's going on, you didn't explain that simple_smile ).

What exactly makes the fetch slow? (I also don't know what you mean with 'GetEntities', is that your own method? )

Frans Bouma | Lead developer LLBLGen Pro
Suchong
User
Posts: 3
Joined: 02-Aug-2019
# Posted on: 05-Aug-2019 13:17:26   

the objective i'm trying to acheive is to seamlessly fetch the 4 table. The next dev would only have to construct one bucket with GlTransactionField and i would modify the bucket so that it would use ICTransactionFields instead. But after a bit of research on my side, i'm afraid it's not possible to modify a bucket after it was created. Because for now it forces us to create 4 RelationBucket with the same condition but with different fields which is what i'm trying to avoid. Yes the GetEntities is our method that call the source adapter to fetch the entity with the according bucket. Thank you for your help !

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 05-Aug-2019 22:49:58   

You want to build a method that masks the creation of 4 predicateBuckets to the developers who would consume your method. In the same sense I don't see a problem of you using 4 different perdicateBuckets in your own method which would accept parameters for different fields to filter. The developers would directly consume your method, which encapsulates everything, and which would be simply coded without the need for any extra code to generalize the predicates.

Suchong
User
Posts: 3
Joined: 02-Aug-2019
# Posted on: 06-Aug-2019 13:35:48   

Yeah exactly! I had no choice but to do what you said, the only things that rubs me the wrong way is that we will have to create 4 different predicate everytime we want to get these entities. I know for one time it is not that time consuming but if we want to fetch these entities 20 times in our application, that makes 80 bucket creation instead of 20 and makes a lot a duplicate code with just one or two different fields (same fields name as well). Thank you for your help!