private bool HasDownstreamChanges(ITrackingCollection refChangeTracker, ITrackable trackableRef, ITrackable item,
                                              EntityReferenceProperty refProp, bool hasDownstreamChanges)
            {
// Get downstream changes
                IEnumerable <ITrackable> refPropItems   = refChangeTracker.Cast <ITrackable>();
                IEnumerable <ITrackable> refPropChanges = GetChanges(refPropItems);

                // Set flag for downstream changes
                bool hasLocalDownstreamChanges =
                    refPropChanges.Any(t => t.TrackingState != TrackingState.Deleted) ||
                    trackableRef.TrackingState == TrackingState.Added ||
                    trackableRef.TrackingState == TrackingState.Modified;

                // Set ref prop to null if unchanged or deleted
                if (!hasLocalDownstreamChanges &&
                    (trackableRef.TrackingState == TrackingState.Unchanged ||
                     trackableRef.TrackingState == TrackingState.Deleted))
                {
                    EntityInfo(item).RefNavPropUnchanged.Add(refProp.Property);
                    return(hasDownstreamChanges);
                }

                // prevent overwrite of hasDownstreamChanges when return from recursion
                hasDownstreamChanges |= hasLocalDownstreamChanges;
                return(hasDownstreamChanges);
            }
示例#2
0
 private void DeferOwnerDetection(ModelType type, EntityReferenceProperty property, NavigationProperty oneNavProp)
 {
     type.AfterInitialize(delegate
     {
         var parentReference = property.PropertyType.Properties[oneNavProp.Name];
         if (parentReference != null && (
                 (oneNavProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One && oneNavProp.ToEndMember.TypeUsage.Facets.Any(f => f.Name == "Nullable" && !(bool)f.Value)) ||
                 (oneNavProp.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One && oneNavProp.FromEndMember.TypeUsage.Facets.Any(f => f.Name == "Nullable" && !(bool)f.Value))))
         {
             ((EntityModelType)type).OwnerProperties[property] = parentReference as ModelReferenceProperty;
         }
     });
 }
 private void DeferOwnerDetection(ModelType type, EntityReferenceProperty property, NavigationProperty oneNavProp)
 {
     type.AfterInitialize(delegate
     {
         var parentReference = property.PropertyType.Properties[oneNavProp.Name];
         if (parentReference != null && (
             (oneNavProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One && oneNavProp.ToEndMember.TypeUsage.Facets.Any(f => f.Name == "Nullable" && !(bool)f.Value)) ||
             (oneNavProp.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One && oneNavProp.FromEndMember.TypeUsage.Facets.Any(f => f.Name == "Nullable" && !(bool)f.Value))))
             ((EntityModelType) type).OwnerProperties[property] = parentReference as ModelReferenceProperty;
     });
 }