RelationPredicateBucket Equality Test

Posts   
 
    
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 21-Nov-2008 14:14:22   

Hello,

This may seem to be a strange question, but...

Is there any way to determine if 2 RelationPredicateBucket instances are equal?

I am not looking to determine if they are references to the same instance rather do they contain the same set of Predicates and Relations?

Thanks.

Harry

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Nov-2008 03:28:02   

Mmm.. disappointed I can think in two options:

  1. Write your own method that evaluate every member int the bucket.
  2. Use DQE and ToQueryText to compare the two resulted queries. Are you using Adapter or SelfServicing?

Maybe would be a better approach... will verify it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 22-Nov-2008 16:39:48   

There's currently no better way.

Frans Bouma | Lead developer LLBLGen Pro
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 03-Dec-2008 16:40:20   

There is ALWAYS a way.... wink

What I had to do was first serialize each object and convert the streams to byte arrays. I then do a compare of the byte arrays using an extension method:

public static bool EqualTo(this byte[] byteArray1, byte[] byteArray2)
        {
            if (byteArray1 == null && byteArray2 != null) { return false; }
            if (byteArray2 == null && byteArray1 != null) { return false; }
            if (byteArray1 != null && byteArray2 != null)
            {
                if (byteArray1.Length != byteArray2.Length) { return false; }
                int i = 0;

                while ((i < byteArray1.Length) && byteArray1[i] == byteArray2[i])
                {
                    i++;
                }
                return i == byteArray1.Length;
            }
            return true;
        }

It may not be pretty and may not be the most efficient way....but it gets the job done. I would hope that in the future there would be a way to do this provided in the generated code for us to use. I first looked at the interpret methods of the predicate classes and realized that that code is almost 80% of what would be needed....

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Dec-2008 17:04:41   

Good job simple_smile

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 03-Dec-2008 21:28:40   

I don't think this is a valid test for equality.

Say you have two predicate expressions

CustomerId = 5 or customerId = 6

and another

CustomerId = 6 or CustomerId = 5

These would serialize to 2 non equal byte arrays wouldn't they?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 03-Dec-2008 21:38:22   

arschr wrote:

These would serialize to 2 non equal byte arrays wouldn't they?

I agree. That is why I said :

It may not be pretty and may not be the most efficient way....but it gets the job done.

In my specific implementation the need for testing for equality is against filters that are generated in the code by the entities. So, in my case, your example would never happen.

I also concede that it does open the door for misuse and/or error if exposed outside of my code. This is why the implementation(s) are internal or protected where appropriate. wink