If you want to compare 2 columns, you have to use a FieldCompareExpressionPredicate, created by PredicateFactory.CompareExpression. You can with that, create a filter like:
WHERE Foo = Bar
where both foo and bar are fields in the same table (or another table in the join).
If you use a FieldCompareValuePredicate (created by PredicateFactory.CompareValue), the value passed in is considered a value, and you can create a filter like:
WHERE Foo = @value
so if you pass in a field index, like MyTableFieldIndex.Bar, it will consider that as a value, not as a field. So your code should look like:
IPredicateExpression customFilter = new PredicateExpression();
customFilter.Add(PredicateFactory.CompareExpression(
RatingFieldIndex.ClassCodeTableId, ComparisonOperator.Equal,
new Expression (EntityFieldFactory.Create(ClassCodesFieldIndex.ClassCodeTableId))));
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.Relations.Add(RatingEntity.Relations.ClassCodeEntityUsingClassCodeId).CustomFilter = customFilter;
ratings = new EntityCollection(new RatingEntityFactory());
adapter.FetchEntityCollection(ratings, filter);