Overriding Equals

4 posts, 0 answers
  1. Wesley
    Wesley avatar
    4 posts
    Member since:
    Mar 2009

    Posted 16 Mar 2009 Link to this post

    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
  2. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 16 Mar 2009 Link to this post

    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.
  3. DevCraft banner
  4. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 16 Mar 2009 Link to this post

    oops, that should be a boolean. 
  5. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 16 Mar 2009 Link to this post

    You could also create multiple extension methods that would allow you test for multiple types of equality.
Back to Top