Yes, I know that the NHibernate documentation says that you should override Equals and GetHashCode, but I get the feeling that this wasn’t what the documentation authors intended:
Even if the base class (e.g. BaseEntity) has a valid logic for calculating GetHashCode based on all identifier properties, NHibernate will complain if the inherited class doesn't implement it. If you're using composite ids, you're oblitaded to do so.
I have been struggling with implementing Equals/GetHashCode, especially when lazy-loaded properties are part of an object's identity. Because then every time Equals or GetHashCode gets called those properties get lazy-loaded. I have posted a question about this on stackoverflow, but haven't yet received an answer that satisfies me 100%.
> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
>
> * You can quote a list.
> * Etc.
Horizontal Rules
Three or more dashes or asterisks:
---
* * *
- - - -
Manual Line Breaks
End a line with two or more spaces:
Roses are red,
Violets are blue.
Fenced Code Blocks
Code blocks delimited by 3 or more backticks or tildas:
```
This is a preformatted
code block
```
Header IDs
Set the id of headings with {#<id>} at end of heading line:
## My Heading {#myheading}
Tables
Fruit |Color
---------|----------
Apples |Red
Pears |Green
Bananas |Yellow
Definition Lists
Term 1
: Definition 1
Term 2
: Definition 2
Footnotes
Body text with a footnote [^1]
[^1]: Footnote text here
Abbreviations
MDD <- will have title
*[MDD]: MarkdownDeep
FUTURE POSTS
Partial writes, IO_Uring and safety - about one day from now
Configuration values & Escape hatches - 5 days from now
What happens when a sparse file allocation fails? - 7 days from now
NTFS has an emergency stash of disk space - 9 days from now
Challenge: Giving file system developer ulcer - 12 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
RECENT SERIES
Challenge
(77): 20 Jan 2025 - What does this code do?
Answer
(13): 22 Jan 2025 - What does this code do?
Comments
This one is a classic. It's also a showcase why code c.q. peer reviews are so important. You catch 'errors' you won't catch with a unit test..
Yeah, it's missing the number 397 in it.
R# would have catch it automatically, and would have shown this code grayed in the VS code editor wnd
Even if the base class (e.g. BaseEntity) has a valid logic for calculating GetHashCode based on all identifier properties, NHibernate will complain if the inherited class doesn't implement it. If you're using composite ids, you're oblitaded to do so.
That being said, this code may not be so wrong.
So is the documentation wrong or the implementer?
A really good one ;-)
@Juan Lopes
You are right, S#arp Architecture's BaseObject class implements general purpose GetHashCode.
sharp-architecture.googlecode.com/.../BaseObjec...
Provided .Equals is implemented by calling down to the base, then this is fine :-D
I have been struggling with implementing Equals/GetHashCode, especially when lazy-loaded properties are part of an object's identity. Because then every time Equals or GetHashCode gets called those properties get lazy-loaded. I have posted a question about this on stackoverflow, but haven't yet received an answer that satisfies me 100%.
http://stackoverflow.com/q/5002670/104750
Comment preview