Ejemplo n.º 1
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected virtual void ValidateOnlyETagConcurrencyToken(
            [NotNull] IModel model,
            [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger)
        {
            foreach (var entityType in model.GetEntityTypes())
            {
                foreach (var property in entityType.GetDeclaredProperties())
                {
                    if (property.IsConcurrencyToken)
                    {
                        var storeName = property.GetJsonPropertyName();
                        if (storeName != "_etag")
                        {
                            throw new InvalidOperationException(
                                      CosmosStrings.NonETagConcurrencyToken(entityType.DisplayName(), storeName));
                        }

                        var etagType = property.GetTypeMapping().Converter?.ProviderClrType ?? property.ClrType;
                        if (etagType != typeof(string))
                        {
                            throw new InvalidOperationException(
                                      CosmosStrings.ETagNonStringStoreType(
                                          property.Name, entityType.DisplayName(), etagType.ShortDisplayName()));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public override void Properties_can_be_made_concurrency_tokens()
 {
     Assert.Equal(
         CosmosStrings.NonETagConcurrencyToken(nameof(Quarks), "Charm"),
         Assert.Throws <InvalidOperationException>(
             () => base.Properties_can_be_made_concurrency_tokens()).Message);
 }
Ejemplo n.º 3
0
        public virtual void Detects_invalid_concurrency_token()
        {
            var modelBuilder = CreateConventionalModelBuilder();

            modelBuilder.Entity <Customer>()
            .ToContainer("Orders")
            .Property <string>("_not_etag")
            .IsConcurrencyToken();

            VerifyError(CosmosStrings.NonETagConcurrencyToken(typeof(Customer).Name, "_not_etag"), modelBuilder);
        }