1- You shouldn't define new fields
2- Don't remove generated code as it will be re generated.
3- Inside the user code region, do as below, remove the relation, re-add it again, and this time set the CustomFilter, and make sure it replaces the ON clause.
Example:
Genetated Code
private void BuildRelationSet()
{
_filterBucket.Relations.ObeyWeakRelations = base.ObeyWeakRelations;
_filterBucket.Relations.Add(CategoryEntity.Relations.ProductEntityUsingCategoryId, "", "", JoinHint.Inner);
_filterBucket.Relations.Add(SupplierEntity.Relations.ProductEntityUsingSupplierId, "", "", JoinHint.Inner);
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalRelations
// __LLBLGENPRO_USER_CODE_REGION_END
OnRelationSetBuilt(_filterBucket.Relations);
}
Modified Genetated Code
private void BuildRelationSet()
{
_filterBucket.Relations.ObeyWeakRelations = base.ObeyWeakRelations;
_filterBucket.Relations.Add(CategoryEntity.Relations.ProductEntityUsingCategoryId, "", "", JoinHint.Inner);
_filterBucket.Relations.Add(SupplierEntity.Relations.ProductEntityUsingSupplierId, "", "", JoinHint.Inner);
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalRelations
((IList)_filterBucket.Relations).RemoveAt(1);
var relation = SupplierEntity.Relations.ProductEntityUsingSupplierId;
relation.CustomFilter = new PredicateExpression(
SupplierFields.SupplierId.SetExpression(new DbFunctionCall("{0} + '000000'", new object[] { SupplierFields.SupplierId }))
== ProductFields.SupplierId);
relation.CustomFilterReplacesOnClause = true;
_filterBucket.Relations.Add(relation, "", "", JoinHint.Inner);
// __LLBLGENPRO_USER_CODE_REGION_END
OnRelationSetBuilt(_filterBucket.Relations);
}