public IGenericBusinessObj GetRelation(System.Data.Objects.DataClasses.IEntityWithRelationships currentObject,
                                               System.Data.Objects.ObjectStateEntry currentState)
        {
            System.Data.Objects.DataClasses.IRelatedEnd currentEnd = GetRelatedEnd(currentObject);

            if (currentEnd == null)
            {
                throw new ApplicationException(string.Format("Could not find {0} on {1}", TargetRoleName, RelationshipName));
            }

            // loaded from DB then call load check to see if loaded before enumerating
            if (currentState.State == System.Data.EntityState.Modified || currentState.State == System.Data.EntityState.Unchanged)
            {
                if (currentEnd.IsLoaded == false)
                {
                    return(null);
                }
            }

            // find the first one and return it
            foreach (object childObject in currentEnd)
            {
                return(childObject as IGenericBusinessObj);
            }

            // if first not found then return
            return(null);
        }
        public override bool Equals(object obj)
        {
            // if the objects are equal
            RelatedObject otherObj = obj as RelatedObject;

            if (otherObj != null)
            {
                return(otherObj.RelationshipName == RelationshipName &&
                       otherObj.TargetRoleName == TargetRoleName);
            }

            System.Data.Objects.DataClasses.IRelatedEnd otherEnd = obj as System.Data.Objects.DataClasses.IRelatedEnd;
            if (otherEnd != null)
            {
                return(otherEnd.RelationshipName == RelationshipName &&
                       otherEnd.TargetRoleName == TargetRoleName);
            }

            return(false);
        }