public EntityNavigationPropertyInfo(NavigationProperty property, EntityRelationshipResolver relationshipResolver) { if (property == null) { throw new ArgumentNullException(nameof(property)); } if (relationshipResolver == null) { throw new ArgumentNullException(nameof(relationshipResolver)); } Property = property; PropertyInfo = (System.Reflection.PropertyInfo)property.MetadataProperties[PropertyInfoMetadataName].Value; ReferencedEntityDeleteBehavior = property.FromEndMember.DeleteBehavior; ReferencedEntityIsDependent = relationshipResolver.DetermineIfEndMemberIsDependent(property); Relationship = relationshipResolver.GetRelationshipType(property); }
public TypeRelationshipInfo(TypeDescriptor relatedTypeDescriptor, EntityRelationshipType entityRelationshipType, PropertyDescriptor relatedProperty) { this.RelatedTypeTypeDescriptor = relatedTypeDescriptor; this.EntityRelationshipType = entityRelationshipType; this.ReferencingProperty = relatedProperty; }
public TypeRelationshipInfo SetOrCreateRelationshipInfo(TypeDescriptor relatedTypeDescriptor, EntityRelationshipType entityRelationshipType, PropertyDescriptor relatedProperty) { TypeRelationshipInfo retval; if (this.relationshipInfos.TryGetValue(relatedTypeDescriptor, out retval)) { retval.EntityRelationshipType = entityRelationshipType; retval.ReferencingProperty = relatedProperty; retval.RelatedTypeTypeDescriptor = relatedTypeDescriptor; return(retval); } retval = new TypeRelationshipInfo(relatedTypeDescriptor, entityRelationshipType, relatedProperty); this.relationshipInfos[relatedTypeDescriptor] = retval; return(retval); }
public TypeRelationshipInfo SetOrCreateRelationshipInfo(TypeDescriptor relatedTypeDescriptor, EntityRelationshipType entityRelationshipType, PropertyDescriptor relatedProperty) { TypeRelationshipInfo retval; if (this.relationshipInfos.TryGetValue(relatedTypeDescriptor, out retval)) { retval.EntityRelationshipType = entityRelationshipType; retval.ReferencingProperty = relatedProperty; retval.RelatedTypeTypeDescriptor = relatedTypeDescriptor; return retval; } retval = new TypeRelationshipInfo(relatedTypeDescriptor, entityRelationshipType, relatedProperty); this.relationshipInfos[relatedTypeDescriptor] = retval; return retval; }
public RelatedDataAccessObjects(IDataAccessObjectAdvanced relatedDataAccessObject, DataAccessModel dataAccessModel, EntityRelationshipType relationshipType, string propertyName) : base(dataAccessModel, null) { this.PropertyName = propertyName; this.RelatedDataAccessObject = relatedDataAccessObject; this.RelationshipType = relationshipType; this.ExtraCondition = this.GetExtraCondition(); this.PersistenceQueryProvider.RelatedDataAccessObjectContext = this; this.BuildInitializeRelatedMethod(); }
private void ShowRelatedView(EntityRelationship entityRelationship) { EntityRelationshipType relationshipType = (EntityRelationshipType)entityRelationship.EntityRelationshipType; var currentEntityRelationRole = entityRelationship.EntityRelationshipRoles.Single(r => r.Entity.PhysicalName == EntityName); string relationTitle = GetLocalizedCaption(currentEntityRelationRole.Entity.PhysicalName) + "-"; if (relationshipType == EntityRelationshipType.OneToMany) { var roleType = (RelationshipRoleType)currentEntityRelationRole.RelationshipRoleType; var relationship = entityRelationship.EntityRelationshipRelationships.Single().Relationship; if (roleType == RelationshipRoleType.OneToMany) { var desiredEntityName = relationship.ReferencingEntity.PhysicalName; var entityId = GetId(_entityListView.SelectedEntity); CriteriaOperator filter = new BinaryOperator(relationship.ReferencingAttribute.Name, entityId, BinaryOperatorType.Equal); var result = DynamicDataServiceContext.GetObjects(desiredEntityName, filter, null); if (result.ToArrayList().Count > 0) { ShowRelatedEntityList(desiredEntityName, relationTitle, filter); } else { XtraMessageBox.Show(Properties.Resources.NoRelatedData, Properties.Resources.Katrin, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { var entityName = relationship.ReferencedEntity.PhysicalName; string desiredPropertyName = relationship.ReferencingAttribute.PhysicalName; var propertyInfo = _entityListView.SelectedEntity.GetType().GetProperty(desiredPropertyName); var id = propertyInfo.GetValue(_entityListView.SelectedEntity, null); if (id != null) { ShowRelatedEntityDetail(entityName, (Guid)id); } else { XtraMessageBox.Show(_entityListView, Properties.Resources.NoRelatedData, Properties.Resources.Katrin, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { var relationshipRole = entityRelationship.EntityRelationshipRoles .Single(r => (RelationshipRoleType)r.RelationshipRoleType == RelationshipRoleType.Relationship); var desiredEntityRole = entityRelationship.EntityRelationshipRoles .Single(r => r != relationshipRole && r != currentEntityRelationRole); var desiredEntityPropertyName = entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship) .Single(r => r.ReferencedEntity.EntityId == desiredEntityRole.Entity.EntityId). ReferencedAttribute.PhysicalName; var knownPropertyName = entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship) .Single(r => r.ReferencedEntity.EntityId == currentEntityRelationRole.Entity.EntityId). ReferencedAttribute.PhysicalName; CriteriaOperator filter = new BinaryOperator(knownPropertyName, GetId(_entityListView.SelectedEntity)); var relationships = DynamicDataServiceContext.GetObjects(relationshipRole.Entity.PhysicalName, filter, null); List <object> desiredEntityIds = new List <object>(); CriteriaOperator relatedFilter = null; for (int index = 0; index < relationships.Count; index++) { var relatedObject = relationships[index]; var propertyInfo = relatedObject.GetType().GetProperty(desiredEntityPropertyName); var desiredEntityId = propertyInfo.GetValue(relatedObject, null); desiredEntityIds.Add(desiredEntityId); relatedFilter |= new BinaryOperator(desiredEntityPropertyName, desiredEntityId); } if (desiredEntityIds.Any()) { if (desiredEntityIds.Count == 1) { ShowRelatedEntityDetail(desiredEntityRole.Entity.PhysicalName, (Guid)desiredEntityIds[0]); } else { ShowRelatedEntityList(desiredEntityRole.Entity.PhysicalName, relationTitle, relatedFilter); } } else { XtraMessageBox.Show(_entityListView, Properties.Resources.NoRelatedData, Properties.Resources.Katrin, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void ShowRelatedView(string relatedObjectName, string objectName, object selectedEntity) { var relationshipRoles = MetadataRepository.EntityRelationshipRoles.Where(role => role.Entity.PhysicalName == objectName && role.NavPanelDisplayOption == 1); EntityRelationship entityRelationship = relationshipRoles.Where(c => c.EntityRelationship.EntityRelationshipRoles .FirstOrDefault(r => r != c && r.RelationshipRoleType != (int)RelationshipRoleType.Relationship && r.Entity.PhysicalName == relatedObjectName) != null).FirstOrDefault().EntityRelationship; EntityRelationshipType relationshipType = (EntityRelationshipType)entityRelationship.EntityRelationshipType; IObjectSpace objectSpace = new ODataObjectSpace(); var currentEntityRelationRole = entityRelationship.EntityRelationshipRoles.Single(r => r.Entity.PhysicalName == objectName); string relationTitle = GetLocationCaption(currentEntityRelationRole.Entity.PhysicalName) + "-"; if (relationshipType == EntityRelationshipType.OneToMany) { var roleType = (RelationshipRoleType)currentEntityRelationRole.RelationshipRoleType; var relationship = entityRelationship.EntityRelationshipRelationships.Single().Relationship; if (roleType == RelationshipRoleType.OneToMany) { var desiredEntityName = relationship.ReferencingEntity.PhysicalName; var entityId = objectSpace.GetObjectId(objectName, selectedEntity); CriteriaOperator filter = new BinaryOperator(relationship.ReferencingAttribute.Name, entityId, BinaryOperatorType.Equal); var result = objectSpace.GetObjects(desiredEntityName, filter, null); if (result.Count > 0) { var parameters = new ActionParameters(relatedObjectName, Guid.Empty, ViewShowType.Show) { { "FixedFilter", filter } }; App.Instance.Invoke(relatedObjectName, "List", parameters); } else { XtraMessageBox.Show(GetLocationCaption("NoRelatedData"), GetLocationCaption("Katrin"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { var entityName = relationship.ReferencedEntity.PhysicalName; string desiredPropertyName = relationship.ReferencingAttribute.PhysicalName; Guid currentId = objectSpace.GetObjectId(objectName, selectedEntity); var currentObject = objectSpace.GetOrNew(objectName, currentId, null); var propertyInfo = currentObject.GetType().GetProperty(desiredPropertyName); var id = propertyInfo.GetValue(currentObject, null); if (id != null) { var relatedObject = objectSpace.GetOrNew(this.Parameter, (Guid)id, string.Empty); if (relatedObject == null) { MessageService.ShowMessage(GetLocationCaption("NoRelatedData")); return; } string detail = "Detail"; var parameters = new ActionParameters(relatedObjectName, (Guid)id, ViewShowType.Show) { { "WorkingMode", EntityDetailWorkingMode.View } }; App.Instance.Invoke(relatedObjectName, detail, parameters); } else { XtraMessageBox.Show(GetLocationCaption("NoRelatedData"), GetLocationCaption("Katrin"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { var relationshipRole = entityRelationship.EntityRelationshipRoles .Single(r => (RelationshipRoleType)r.RelationshipRoleType == RelationshipRoleType.Relationship); var desiredEntityRole = entityRelationship.EntityRelationshipRoles .Single(r => r != relationshipRole && r != currentEntityRelationRole); var desiredEntityPropertyName = entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship) .Single(r => r.ReferencedEntity.EntityId == desiredEntityRole.Entity.EntityId). ReferencedAttribute.PhysicalName; var knownPropertyName = entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship) .Single(r => r.ReferencedEntity.EntityId == currentEntityRelationRole.Entity.EntityId). ReferencedAttribute.PhysicalName; CriteriaOperator filter = new BinaryOperator(knownPropertyName, objectSpace.GetObjectId(objectName, selectedEntity)); var relationships = objectSpace.GetObjects(relationshipRole.Entity.PhysicalName, filter, null); List <object> desiredEntityIds = new List <object>(); CriteriaOperator relatedFilter = null; for (int index = 0; index < relationships.Count; index++) { var relatedObject = relationships[index]; var propertyInfo = relatedObject.GetType().GetProperty(desiredEntityPropertyName); var desiredEntityId = propertyInfo.GetValue(relatedObject, null); desiredEntityIds.Add(desiredEntityId); relatedFilter |= new BinaryOperator(desiredEntityPropertyName, desiredEntityId); } if (desiredEntityIds.Any()) { if (desiredEntityIds.Count == 1) { string detail = "Detail"; var parameters = new ActionParameters(relatedObjectName, (Guid)desiredEntityIds[0], ViewShowType.Show) { { "WorkingMode", EntityDetailWorkingMode.View } }; App.Instance.Invoke(desiredEntityRole.Entity.PhysicalName, detail, parameters); } else { var parameters = new ActionParameters(desiredEntityRole.Entity.PhysicalName, Guid.Empty, ViewShowType.Show) { { "FixedFilter", relatedFilter } }; App.Instance.Invoke(desiredEntityRole.Entity.PhysicalName, "List", parameters); } } else { XtraMessageBox.Show(GetLocationCaption("NoRelatedData"), GetLocationCaption("Katrin"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } }