I've just been trying to find a bug I introduced when doing some optimisation work, and I've tracked it down to what seems like a pretty nasty gotcha to watch out for. The issue reduces to the following example:
CompanyEntity company;
company = new CompanyEntity(123);
// IPrefetchPath path = new PrefetchPath((int)EntityType.CompanyEntity);
// path.Add(CompanyEntity.PrefetchPathDepartment).SubPath.Add(DepartmentEntity.PrefetchPathManager);
// company = new CompanyEntity(123, path);
foreach (DepartmentEntity department in company.Department)
{
Email(department.Manager.EmailAddress);
}
Where Department joins to one Manager on a char based ManagerID.
As is, the code pulls out the department managers, matching in a case-insensitive fashion, but when the three removed lines are included with the intention of adding a content-neutral performance enhancement, the resulting CompanyEntity is changed such that its departments only match managers in a case sensitive way, leaving an object reference error on department.Manager where ManagerId cases do not match.
Cheers, JS.