ValueObject is not equivalent to a Castle.Proxies ValueObject
See original GitHub issueI’m getting data from an external source that provides a set of type_codes. I have the type_codes as entities in a table. So I’m constructing an object with child objects that each map to the type_code table. In this case an Animal object mapping to Breeds, in which each breed has a breed code.
As this is a fairly long list, I’m going var allBreeds = _context.Breeds.ToList() to get the list of Breeds. Breed has a BreedType ValueObject on it with properties Code and DisplayName. This ValueObject only uses Code for its EqualityComponent. So I form a BreedType ValueObject with the breed_code from the external source and then try to find the reference Breed from allBreeds as it has the entity Id for that breed in the database. The problem seems to be that each breedType is a Castle.Procies.BreedTypeProxy, rather than a straight BreedType, so when I go
var referenceBreed = allBreeds.SingleOrDefault(x => x.BreedType == constructedBreedType);
two ValueObjects with the same code are not equivalent. How can I make them equivalent, or should I be doing this a different way?
The reason for pulling all the breeds back is so that I’m not doing lots of calls back to the database.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
I see the issue now. The original implementation of VO was tailored toward NHibernate, where the ORM doesn’t create proxies on top of value objects. Pushed a fix, should be published soon as v2.11.5. Let me know if this fixes the issue.
@vkhorikov Thanks for the quick update to the library, this appears to have fixed my issue.