This is a migrated thread and some comments may be shown as answers.

Overriding Equals

3 Answers 43 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wesley
Top achievements
Rank 1
Wesley asked on 16 Mar 2009, 04:52 PM
If I want to override equals in my persistent classes to simply compare primary keys

1) is there already some kind of static method or helper class somewhere that does this in OpenAccess
2) if not, how do I get at the object ids if I had Telerik ORM handle the Ids for me (forward mapping)?

Thanks

3 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 17 Mar 2009, 03:24 AM
I haven't tested this code, but something along these lines should work:

  Public Shared Operator =(ByVal a As Category, _
                                          ByVal b As Category) As Integer
        Dim result As Boolean = False
        'Get OID for object A
        Dim oidA As IObjectId = scope.GetObjectId(a)
        Dim oidB As IObjectId = scope.GetObjectId(b)
        If oidA Is oidB Then result = True
        Return result
    End Operator

I'm not sure about the exact C# syntax, but it should be equally easy.  Note that you do need the scope.
It should just be a matter of basic operator overloading.  You could, of course, stick this in an extention method if you really wanted to.

Let me know if that doesn't work.
0
Chris
Top achievements
Rank 1
answered on 17 Mar 2009, 03:25 AM
oops, that should be a boolean. 
0
Chris
Top achievements
Rank 1
answered on 17 Mar 2009, 03:26 AM
You could also create multiple extension methods that would allow you test for multiple types of equality.
Tags
Getting Started
Asked by
Wesley
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Share this question
or