Follow Up: Why Isn’t My Linq Query Working

My friend Bill gave me some good feedback on my last post where I talked about making sure you have some kind of value equality implementation on your business objects so Linq queries work the way you expect them to.  Bill informed me that anonymous types’ default implementation of Equals() is very similar to that of structs.  Two objects of an anonymous type are considered equals if all of their properties’ Equals() calls return true.  So if you can get away with using anonymous types in your Linq queries, things should work as expected.  Be careful, though, if you have properties in your anonymous types that are using reference equality.  If so, you may still see some strange behavior.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s