Filter via relations using SelfServicing?

Posts   
 
    
Posts: 65
Joined: 07-Dec-2005
# Posted on: 07-Dec-2005 17:30:35   

Good afternoon, all!

I'm new to the boards, but I've been using LLBLGen generated code for a month or two now, and right now I am working on a dynamic filter engine that can generate a predicate and prefetch path based upon the entities in my class, and the relations on those entities.

However, now that the rubber is meeting the road, I am having trouble getting my filter to work across relations. Does anyone have an example of constructing a Predicate or PredicateExpression using entity relations in a SelfServicing project? Any help is greatly appreciated!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2005 18:23:27   

What have you tried yourself what failed? Perhaps it's a small thing that needs to be adjusted. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 65
Joined: 07-Dec-2005
# Posted on: 07-Dec-2005 20:35:49   

Here are the general steps that I followed:

Create new SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression, initialized to null;

Assign a new PredicateExpression based on the comparison (greater than) of a field that is on the base entity.

AND the expression with a comparison of a field on a related entity

Create a PrefetchPath for the base entity.

Create a RelationCollection and add the relation that links the base entity to the related entity

Add to the PrefetchPath the path for the related entity, 0 maxItems, the previously created predicate, and the RelationCollection

Call GetMulti()

Get an exception

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2005 22:14:16   

WHat kind of exception, could you also paste the stacktrace? It would be great if you could paste actual code so we can have a clear look at what you've done what lead to the exception.

Also, as this is caused by GetMulti, be sure your application's .config file has the connection string defined in the appSettings, as generated into the generated code's app.config file.

Frans Bouma | Lead developer LLBLGen Pro
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 08-Dec-2005 02:41:39   

Can you post your code that is generating this error?

Posts: 65
Joined: 07-Dec-2005
# Posted on: 08-Dec-2005 15:17:30   

SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression predicate=null;

        predicate=new SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression([base entity date field taken from the fields class for this entity inside HelperClasses]>"10/1/2005");

        predicate=predicate & [related entity int field]==29;

        SD.LLBLGen.Pro.ORMSupportClasses.IPrefetchPath path=new SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPath((int)[enum type for the base entity]);

        SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection col=new SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection();

        [relations class for the base entity] gr=new [relations class for the base entity]();

        col.Add(gr.[relation for these two entities]);

        [collection for the base entity] gc=new [collection for the base entity]();

        gc.GetMulti(predicate,path);

(The items in square brackets [] are comments replacing industry-specific names, terms, and code; they shouldn't be relevant to troubleshooting)

Posts: 65
Joined: 07-Dec-2005
# Posted on: 08-Dec-2005 15:40:13   

Never mind, thanks for trying, but I figured it out!

I'd been using a prefetch path, since that is what I had seen in another post. However, I needed to include the relationcollection in the GetMulti, rather than in a prefetch path.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Dec-2005 15:54:19   

Another question please:

Would you enable DQE tracing and send us the Query it generates?

Note: DQE tracing can be enabled in the .config file, see 'troubleshooting and debugging'.

Thanks a lot