I have an application that uses WCF for all DataAccess. It returns some business objects and it has some operations.
Should this code exist in my Client or in my Service? If in the service, HOW should I implement it? Can I simply add it as an interface to my business object? Will that come through the WCF Service Proxy Code?
(This is a sample from MSDN, I'd like to get some feedback before I implement my own, but it will be 99% the same)
// Custom comparer for the Product class.
class ProductComparer : IEqualityComparer<Product>
{
// Products are equal if their names and product numbers are equal.
public bool Equals(Product x, Product y)
{
// Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
// Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
// Check whether the products' properties are equal.
return x.Code == y.Code && x.Name == y.Name;
}
// If Equals() returns true for a pair of objects,
// GetHashCode must return the same value for these objects.
public int GetHashCode(Product product)
{
// Check whether the object is null.
if (Object.ReferenceEquals(product, null)) return 0;
// Get the hash code for the Name field if it is not null.
int hashProductName = product.Name == null ? 0 : product.Name.GetHashCode();
// Get the hash code for the Code field.
int hashProductCode = product.Code.GetHashCode();
// Calculate the hash code for the product.
return hashProductName ^ hashProductCode;
}
}