internal List <Field> GetNavigationFields() { // was: FirstOrDefault var hierarchy = RelationshipsAsChild.SingleOrDefault(r => r.Hierarchy); var result = new List <Field>(); foreach (var field in KeyFields.OrderBy(f => f.SortPriority)) { // exclude field if hierarchichal parent has field of same name // this is used to ignore/exclude a multi-field primary key on an entity that // is a hierarchical child of the repeated parent key. // example: WRC project: customer is hierarchical parent of consumption. // key on consumption = customer + consumptionSet. // url must NOT be: customer/:customerId/consumption/:customerId/:consumptionSetId // as that would repeat the :customerId param, which is not allowed. // because it is hierarchical, just need the parent's :customerId if (hierarchy == null || !hierarchy.ParentEntity.KeyFields.Any(f => f.Name == field.Name)) { result.Add(field); } } if (hierarchy != null) { var parentResult = hierarchy.ParentEntity.GetNavigationFields(); result.InsertRange(0, parentResult); } return(result); }
internal List <Field> GetNavigationFields() { var result = new List <Field>(); foreach (var field in KeyFields.OrderBy(f => f.SortPriority)) { result.Add(field); } // todo: if more than one relationship, will this FirstOrDefault randomly choose the wrong one? var relationship = RelationshipsAsChild.FirstOrDefault(r => r.Hierarchy); if (relationship != null) { var parentResult = relationship.ParentEntity.GetNavigationFields(); result.InsertRange(0, parentResult); } return(result); }