コード例 #1
0
        public void SetValueWithoutTypeCheck(PropertyAccessor propertyAccessor, ClientTransaction transaction, object value)
        {
            ArgumentUtility.CheckNotNull("propertyAccessor", propertyAccessor);
            ArgumentUtility.CheckNotNull("transaction", transaction);
            var newRelatedObject = ArgumentUtility.CheckType <DomainObject> ("value", value);

            var endPointID = CreateRelationEndPointID(propertyAccessor);
            var endPoint   = (IObjectEndPoint)transaction.DataManager.GetRelationEndPointWithLazyLoad(endPointID);

            if (newRelatedObject != null && transaction.RootTransaction != newRelatedObject.RootTransaction)
            {
                var formattedMessage = String.Format(
                    "Property '{1}' of DomainObject '{2}' cannot be set to DomainObject '{0}'.",
                    newRelatedObject.ID,
                    endPoint.Definition.PropertyName,
                    endPoint.ObjectID);
                throw new ClientTransactionsDifferException(formattedMessage + " The objects do not belong to the same ClientTransaction.");
            }

            DomainObjectCheckUtility.EnsureNotDeleted(endPoint.GetDomainObjectReference(), endPoint.ClientTransaction);
            if (newRelatedObject != null)
            {
                DomainObjectCheckUtility.EnsureNotDeleted(newRelatedObject, endPoint.ClientTransaction);
                CheckNewRelatedObjectType(endPoint, newRelatedObject);
            }

            var setCommand = endPoint.CreateSetCommand(newRelatedObject);
            var bidirectionalModification = setCommand.ExpandToAllRelatedObjects();

            bidirectionalModification.NotifyAndPerform();
        }
コード例 #2
0
        public void SetValueWithoutTypeCheck(PropertyAccessor propertyAccessor, ClientTransaction transaction, object value)
        {
            ArgumentUtility.CheckNotNull("propertyAccessor", propertyAccessor);
            ArgumentUtility.CheckNotNull("transaction", transaction);
            var newCollection = ArgumentUtility.CheckNotNullAndType <DomainObjectCollection> ("value", value);

            DomainObjectCheckUtility.EnsureNotDeleted(propertyAccessor.DomainObject, transaction);

            RelationEndPointID id = CreateRelationEndPointID(propertyAccessor);
            var endPoint          = (ICollectionEndPoint)transaction.DataManager.GetRelationEndPointWithLazyLoad(id);

            if (newCollection.AssociatedEndPointID != null && newCollection.AssociatedEndPointID != endPoint.ID)
            {
                throw new ArgumentException("The given collection is already associated with an end point.", "value");
            }

            if (newCollection.RequiredItemType != endPoint.Collection.RequiredItemType &&
                !newCollection.IsReadOnly &&
                !endPoint.Collection.IsReadOnly)
            {
                throw new InvalidOperationException("The given collection has a different item type than the end point's current opposite collection.");
            }

            if (newCollection.GetType() != endPoint.Collection.GetType())
            {
                var message = string.Format(
                    "The given collection ('{0}') is not of the same type as the end point's current opposite collection ('{1}').",
                    newCollection.GetType(),
                    endPoint.Collection.GetType());
                throw new InvalidOperationException(message);
            }

            var command = endPoint.CreateSetCollectionCommand(newCollection);
            var bidirectionalModification = command.ExpandToAllRelatedObjects();

            bidirectionalModification.NotifyAndPerform();
        }