Open GoogleCodeExporter opened 9 years ago
Yes,
I believe it should look at all non computed columns. Also, it should implement
a GetHashCode override. What do you think with this proposal?
Would you mind submitting a patch for this?
Original comment by bniemyjski
on 11 Apr 2012 at 4:45
I'm working on this. Will add the update when I get it working.
Original comment by ibflyfis...@yahoo.com
on 11 Apr 2012 at 11:33
Thanks for helping :). It means a lot.
Original comment by bniemyjski
on 12 Apr 2012 at 1:31
Original comment by bniemyjski
on 12 Apr 2012 at 1:31
[deleted comment]
Blake,
Turns out that NHibernate accesses the GetHashCode after loading just the key
properties. So when it loads the rest of the data the HashCode changes. This
causes a problem on update because it thinks that the ID has changed and won't
allow that. I'm going to post this on the NHibernate forums and see what they
say.
So for now I have implemented the Equals and GetHashCode in a similar fashion
to what was originally in the file but moved it so that its generated for all
objects not just those with Composite Keys.
I added an "Equivalent" method that does do a field by field comparison. I
also added formatting to the call so that each comparison is on its own line
and is easier to read.
I tried to keep everything consistent with how the file was written. Let me
know if you have an suggestions or changes.
Thanks
dbl
Original comment by ibflyfis...@yahoo.com
on 12 Apr 2012 at 5:11
Attachments:
Hello,
Thanks for your attached changes.
I've created a patch for this. Is there any chance you could change the
template logic for GetEquals and GetHashCode. I think it would make more sense
to just place all the generation logic where it belongs, which also saves from
doing new line insertion. Also you can just override the GetHashCode() and
Equals() methods in your derived entities which makes adding additional methods
pointless (gotta love the original creator...). What do you think?
Original comment by bniemyjski
on 19 Apr 2012 at 7:41
Attachments:
I had thought about doing that but two things:
I am using the GetEquals to build the GetEquivilant. - the Entity there
separates the properties that are part of the key from the other properties.
I was trying to use the structure/format that was already in the file.
I can get rid of the GetEquivilant and GetGetHashCode but maybe keep the
GetEquals unless you have a better idea.
When I'm done do you just want me to attach it here?
I also found where all the cref references point to the "Account" class instead
of the actual class. I've fixed that as well.
Original comment by ibflyfis...@gmail.com
on 3 May 2012 at 4:37
Hello,
Yes, please attach here. Can you also please update the GetHashCode
implementation too :D.
Original comment by bniemyjski
on 3 May 2012 at 4:52
Also after looking at it the newline piece for me is a readability issue. It
would still be used if you moved the code up into the actual functions so that
each "operation" is on its own line. I understand if you don't want it in the
templates but I like the readability of it that way.
Original comment by ibflyfis...@gmail.com
on 3 May 2012 at 4:58
Not sure what you mean about update the GetHashCode implementation? If you are
referring to including all properties instead of just the key properties, I
haven't resolved the issue where NHibernate and so I've left that
implementation basically the way it was.
Original comment by ibflyfis...@gmail.com
on 3 May 2012 at 5:16
Yes, I would think the GetHashCode implementation would be calculated using the
same properties as equals.
Original comment by bniemyjski
on 7 May 2012 at 4:28
Original issue reported on code.google.com by
ibflyfis...@gmail.com
on 30 Mar 2012 at 3:52