示例#1
0
        public virtual void Detects_changed_only_notifying_entities(ChangeTrackingStrategy changeTrackingStrategy)
        {
            var model      = new Model();
            var entityType = model.AddEntityType(typeof(ChangedOnlyEntity));
            var id         = entityType.AddProperty("Id");

            entityType.SetPrimaryKey(id);

            model.ChangeTrackingStrategy = changeTrackingStrategy;

            VerifyError(
                CoreStrings.ChangeTrackingInterfaceMissing("ChangedOnlyEntity", changeTrackingStrategy, "INotifyPropertyChanging"),
                model);
        }
        private static INotifyPropertyChanged AsINotifyPropertyChanged(
            InternalEntityEntry entry,
            IEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            if (!(entry.Entity is INotifyPropertyChanged changed))
            {
                throw new InvalidOperationException(
                          CoreStrings.ChangeTrackingInterfaceMissing(
                              entityType.DisplayName(), changeTrackingStrategy, nameof(INotifyPropertyChanged)));
            }

            return(changed);
        }
示例#3
0
        private static IModel BuildModel(
            ChangeTrackingStrategy changeTrackingStrategy = ChangeTrackingStrategy.ChangingAndChangedNotifications)
        {
            var builder = InMemoryTestHelpers.Instance.CreateConventionBuilder();

            builder.Entity <FullNotificationEntity>(b =>
            {
                b.Ignore(e => e.NotMapped);
                b.HasMany(e => e.RelatedCollection).WithOne(e => e.Related).HasForeignKey(e => e.Fk);
                b.HasChangeTrackingStrategy(changeTrackingStrategy);
            });

            return(builder.Model);
        }
示例#4
0
        public virtual void Detects_changed_only_notifying_entities(ChangeTrackingStrategy changeTrackingStrategy)
        {
            var model      = CreateConventionlessModelBuilder().Model;
            var entityType = model.AddEntityType(typeof(ChangedOnlyEntity));
            var id         = entityType.AddProperty("Id", null);

            entityType.SetPrimaryKey(id);

            model.SetChangeTrackingStrategy(changeTrackingStrategy);

            VerifyError(
                CoreStrings.ChangeTrackingInterfaceMissing("ChangedOnlyEntity", changeTrackingStrategy, "INotifyPropertyChanging"),
                model);
        }
        private static INotifyCollectionChanged AsINotifyCollectionChanged(
            InternalEntityEntry entry,
            INavigation navigation,
            IEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            if (!(navigation.GetCollectionAccessor()?.GetOrCreate(entry.Entity) is INotifyCollectionChanged notifyingCollection))
            {
                throw new InvalidOperationException(
                          CoreStrings.NonNotifyingCollection(navigation.Name, entityType.DisplayName(), changeTrackingStrategy));
            }

            return(notifyingCollection);
        }
        /// <summary>
        ///     Sets the change tracking strategy to use for this entity type. This strategy indicates how the
        ///     context detects changes to properties for an instance of the entity type.
        /// </summary>
        /// <param name="entityType"> The entity type to set the change tracking strategy for. </param>
        /// <param name="changeTrackingStrategy"> The strategy to use. </param>
        public static void SetChangeTrackingStrategy(
            [NotNull] this IMutableEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            Check.NotNull(entityType, nameof(entityType));

            var errorMessage = entityType.CheckChangeTrackingStrategy(changeTrackingStrategy);

            if (errorMessage != null)
            {
                throw new InvalidOperationException(errorMessage);
            }

            entityType[CoreAnnotationNames.ChangeTrackingStrategy] = changeTrackingStrategy;
        }
示例#7
0
        private static INotifyPropertyChanging AsINotifyPropertyChanging(
            InternalEntityEntry entry,
            IEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            var changing = entry.Entity as INotifyPropertyChanging;

            if (changing == null)
            {
                throw new InvalidOperationException(
                          CoreStrings.ChangeTrackingInterfaceMissing(
                              entityType.DisplayName(), changeTrackingStrategy, nameof(INotifyPropertyChanging)));
            }

            return(changing);
        }
        /// <summary>
        ///     Sets the change tracking strategy to use for this entity type. This strategy indicates how the
        ///     context detects changes to properties for an instance of the entity type.
        /// </summary>
        /// <param name="entityType"> The entity type to set the change tracking strategy for. </param>
        /// <param name="changeTrackingStrategy"> The strategy to use. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        public static void SetChangeTrackingStrategy(
            [NotNull] this IConventionEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy,
            bool fromDataAnnotation = false)
        {
            Check.NotNull(entityType, nameof(entityType));

            var errorMessage = entityType.CheckChangeTrackingStrategy(changeTrackingStrategy);

            if (errorMessage != null)
            {
                throw new InvalidOperationException(errorMessage);
            }

            entityType.SetAnnotation(CoreAnnotationNames.ChangeTrackingStrategy, changeTrackingStrategy, fromDataAnnotation);
        }
    private static INotifyCollectionChanged AsINotifyCollectionChanged(
        InternalEntityEntry entry,
        INavigationBase navigation,
        IEntityType entityType,
        ChangeTrackingStrategy changeTrackingStrategy)
    {
        if (navigation.GetCollectionAccessor()
            ?.GetOrCreate(entry.Entity, forMaterialization: false) is not INotifyCollectionChanged notifyingCollection)
        {
            var collectionType = navigation.GetCollectionAccessor()
                                 ?.GetOrCreate(entry.Entity, forMaterialization: false).GetType().DisplayName(fullName: false);
            throw new InvalidOperationException(
                      CoreStrings.NonNotifyingCollection(navigation.Name, entityType.DisplayName(), collectionType, changeTrackingStrategy));
        }

        return(notifyingCollection);
    }
        public IMutableModel BuildModel(
            ChangeTrackingStrategy fullNotificationStrategy = ChangeTrackingStrategy.ChangingAndChangedNotifications)
        {
            var builder = InMemoryTestHelpers.Instance.CreateConventionBuilder();

            builder.HasChangeTrackingStrategy(fullNotificationStrategy);

            builder.Entity <Wotty>()
            .HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot);

            builder.Entity <NotifyingWotty>()
            .HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangedNotifications);

            builder.Entity <FullyNotifyingWotty>()
            .HasChangeTrackingStrategy(fullNotificationStrategy)
            .Property(e => e.ConcurrentPrimate)
            .IsConcurrencyToken();

            return(builder.Model);
        }
 /// <summary>
 ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
 ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
 /// </summary>
 /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public new virtual ReferenceOwnershipBuilder <TEntity, TRelatedEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => (ReferenceOwnershipBuilder <TEntity, TRelatedEntity>)base.HasChangeTrackingStrategy(changeTrackingStrategy);
示例#12
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public static string CheckChangeTrackingStrategy([NotNull] this IEntityType entityType, ChangeTrackingStrategy value)
        {
            if (entityType.ClrType != null)
            {
                if (value != ChangeTrackingStrategy.Snapshot &&
                    !typeof(INotifyPropertyChanged).GetTypeInfo().IsAssignableFrom(entityType.ClrType.GetTypeInfo()))
                {
                    return(CoreStrings.ChangeTrackingInterfaceMissing(entityType.DisplayName(), value, nameof(INotifyPropertyChanged)));
                }

                if ((value == ChangeTrackingStrategy.ChangingAndChangedNotifications ||
                     value == ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues) &&
                    !typeof(INotifyPropertyChanging).GetTypeInfo().IsAssignableFrom(entityType.ClrType.GetTypeInfo()))
                {
                    return(CoreStrings.ChangeTrackingInterfaceMissing(entityType.DisplayName(), value, nameof(INotifyPropertyChanging)));
                }
            }

            return(null);
        }
示例#13
0
 public ProxyGenerationContext(
     ChangeTrackingStrategy changeTrackingStrategy)
     : base("ProxyGenerationContext", false, true, true, changeTrackingStrategy)
 {
 }
示例#14
0
 public abstract TestOwnedNavigationBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy);
        /// <summary>
        ///     Configures the default <see cref="ChangeTrackingStrategy" /> to be used for this model.
        ///     This strategy indicates how the context detects changes to properties for an instance of an entity type.
        /// </summary>
        /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
        /// <returns>
        ///     The same <see cref="ModelBuilder" /> instance so that additional configuration calls can be chained.
        /// </returns>
        public virtual ModelBuilder HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
        {
            Builder.Metadata.SetChangeTrackingStrategy(changeTrackingStrategy);

            return(this);
        }
 /// <summary>
 ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
 ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
 /// </summary>
 /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public new virtual OwnedNavigationBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => (OwnedNavigationBuilder <TEntity, TDependentEntity>)base.HasChangeTrackingStrategy(changeTrackingStrategy);
示例#17
0
 public PrimateContext(ChangeTrackingStrategy fullNotificationStrategy = ChangeTrackingStrategy.ChangingAndChangedNotifications)
 {
     _fullNotificationStrategy = fullNotificationStrategy;
 }
 public abstract TestReferenceOwnershipBuilder <TEntity, TRelatedEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy);
示例#19
0
        /// <summary>
        ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
        ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
        /// </summary>
        /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual EntityTypeBuilder HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
        {
            Builder.Metadata.ChangeTrackingStrategy = changeTrackingStrategy;

            return(this);
        }
 /// <summary>
 ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
 ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
 /// </summary>
 /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public new virtual CollectionOwnershipBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => (CollectionOwnershipBuilder <TEntity, TDependentEntity>)base.HasChangeTrackingStrategy(changeTrackingStrategy);
 public override TestCollectionOwnershipBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => Wrap(CollectionOwnershipBuilder.HasChangeTrackingStrategy(changeTrackingStrategy));
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public static string CheckChangeTrackingStrategy([NotNull] this IEntityType entityType, ChangeTrackingStrategy value)
        {
            if (entityType.ClrType != null)
            {
                if (value != ChangeTrackingStrategy.Snapshot
                    && !typeof(INotifyPropertyChanged).GetTypeInfo().IsAssignableFrom(entityType.ClrType.GetTypeInfo()))
                {
                    return CoreStrings.ChangeTrackingInterfaceMissing(entityType.DisplayName(), value, typeof(INotifyPropertyChanged).Name);
                }

                if ((value == ChangeTrackingStrategy.ChangingAndChangedNotifications
                     || value == ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues)
                    && !typeof(INotifyPropertyChanging).GetTypeInfo().IsAssignableFrom(entityType.ClrType.GetTypeInfo()))
                {
                    return CoreStrings.ChangeTrackingInterfaceMissing(entityType.DisplayName(), value, typeof(INotifyPropertyChanging).Name);
                }
            }

            return null;
        }
        public IMutableModel BuildModel(
            ChangeTrackingStrategy fullNotificationStrategy = ChangeTrackingStrategy.ChangingAndChangedNotifications)
        {
            var builder = TestHelpers.Instance.CreateConventionBuilder();

            builder.HasChangeTrackingStrategy(fullNotificationStrategy);

            builder.Entity<Wotty>()
                .HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot);

            builder.Entity<NotifyingWotty>()
                .HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangedNotifications);

            builder.Entity<FullyNotifyingWotty>()
                .HasChangeTrackingStrategy(fullNotificationStrategy)
                .Property(e => e.ConcurrentPrimate)
                .IsConcurrencyToken();

            return builder.Model;
        }
 public override TestEntityTypeBuilder <TEntity> HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
 => Wrap(EntityTypeBuilder.HasChangeTrackingStrategy(changeTrackingStrategy));
 public override TestReferenceOwnershipBuilder <TEntity, TRelatedEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => Wrap(ReferenceOwnershipBuilder.HasChangeTrackingStrategy(changeTrackingStrategy));
        private static INotifyCollectionChanged AsINotifyCollectionChanged(
            InternalEntityEntry entry,
            INavigation navigation,
            IEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            var notifyingCollection = navigation.GetCollectionAccessor().GetOrCreate(entry.Entity) as INotifyCollectionChanged;
            if (notifyingCollection == null)
            {
                throw new InvalidOperationException(
                    CoreStrings.NonNotifyingCollection(navigation.Name, entityType.DisplayName(), changeTrackingStrategy));
            }

            return notifyingCollection;
        }
示例#27
0
        public virtual void Passes_for_changed_only_entities_with_snapshot_or_changed_only_tracking(ChangeTrackingStrategy changeTrackingStrategy)
        {
            var model      = new Model();
            var entityType = model.AddEntityType(typeof(ChangedOnlyEntity));
            var id         = entityType.AddProperty("Id");

            entityType.SetPrimaryKey(id);

            model.ChangeTrackingStrategy = changeTrackingStrategy;

            Validate(model);
        }
 /// <summary>
 ///     Sets the default change tracking strategy to use for entities in the model. This strategy indicates how the
 ///     context detects changes to properties for an instance of an entity type.
 /// </summary>
 /// <param name="model"> The model to set the default change tracking strategy for. </param>
 /// <param name="changeTrackingStrategy"> The strategy to use. </param>
 public static void SetChangeTrackingStrategy(
     [NotNull] this IMutableModel model,
     ChangeTrackingStrategy changeTrackingStrategy)
 => Check.NotNull(model, nameof(model)).AsModel().ChangeTrackingStrategy = changeTrackingStrategy;
示例#29
0
 /// <summary>
 ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
 ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
 /// </summary>
 /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
 /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
 public new virtual EntityTypeBuilder <TEntity> HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
 => (EntityTypeBuilder <TEntity>)base.HasChangeTrackingStrategy(changeTrackingStrategy);
        /// <summary>
        ///     Configures the <see cref="ChangeTrackingStrategy" /> to be used for this entity type.
        ///     This strategy indicates how the context detects changes to properties for an instance of the entity type.
        /// </summary>
        /// <param name="changeTrackingStrategy"> The change tracking strategy to be used. </param>
        /// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
        public virtual ReferenceOwnershipBuilder HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
        {
            RelatedEntityType.Builder.Metadata.ChangeTrackingStrategy = changeTrackingStrategy;

            return(this);
        }
 public abstract TestEntityTypeBuilder <TEntity> HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy);
示例#32
0
 public override TestOwnedNavigationBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy)
 => Wrap <TEntity, TDependentEntity>(OwnedNavigationBuilder.HasChangeTrackingStrategy(changeTrackingStrategy));
 public abstract TestCollectionOwnershipBuilder <TEntity, TDependentEntity> HasChangeTrackingStrategy(
     ChangeTrackingStrategy changeTrackingStrategy);
        private static INotifyPropertyChanging AsINotifyPropertyChanging(
            InternalEntityEntry entry,
            IEntityType entityType,
            ChangeTrackingStrategy changeTrackingStrategy)
        {
            var changing = entry.Entity as INotifyPropertyChanging;
            if (changing == null)
            {
                throw new InvalidOperationException(
                    CoreStrings.ChangeTrackingInterfaceMissing(
                        entityType.DisplayName(), changeTrackingStrategy, typeof(INotifyPropertyChanging).Name));
            }

            return changing;
        }