예제 #1
0
        public static OwnedNavigationBuilder <TEntity, TRoute> ConfigureRoute <TEntity, TRoute>(
            [NotNull] this OwnedNavigationBuilder <TEntity, TRoute> builder,
            [CanBeNull] string tablePrefix = "",
            [CanBeNull] string schema      = null)
            where TEntity : class
            where TRoute : Route
        {
            builder.ToTable(tablePrefix + "Routes", schema);

            builder
            .Property(p => p.DisplayName)
            .HasMaxLength(RouteConsts.MaxDisplayNameLength)
            .HasColumnName(nameof(Route.DisplayName))
            .IsRequired();
            builder
            .Property(p => p.Name)
            .HasMaxLength(RouteConsts.MaxNameLength)
            .HasColumnName(nameof(Route.Name))
            .IsRequired();
            builder
            .Property(p => p.Path)
            .HasMaxLength(RouteConsts.MaxPathLength)
            .HasColumnName(nameof(Route.Path));
            builder
            .Property(p => p.Redirect)
            .HasMaxLength(RouteConsts.MaxRedirectLength)
            .HasColumnName(nameof(Route.Redirect));

            return(builder);
        }
예제 #2
0
 public static void Setup <T>(OwnedNavigationBuilder <T, ClubMembership> entity) where T : class
 {
     entity.WithOwner();
     entity.Property(e => e.ClubName).IsRequired();
     entity.Property(e => e.MembershipNumber).IsRequired();
     entity.Property(e => e.Expiry).IsRequired();
 }
예제 #3
0
 public static void Setup <T>(OwnedNavigationBuilder <T, AcceptDeclaration> entity) where T : class
 {
     entity.WithOwner();
     entity.Property(e => e.IsAccepted).IsRequired();
     entity.Property(e => e.Email).IsRequired();
     entity.Property(e => e.Timestamp).IsRequired();
 }
        public static OwnedNavigationBuilder <TOwner, Money> BuildMoney <TOwner>(this OwnedNavigationBuilder <TOwner, Money> builder, string prefix = null, bool required = false)
            where TOwner : class
        {
            builder.Property(e => e.Amount).HasColumnType("decimal(16,6)").HasColumnName($"{prefix}value");
            builder.Property(e => e.Currency).IsCode(3, false).HasColumnName($"{prefix}currency");

            return(builder);
        }
        public static OwnedNavigationBuilder <TOwner, GeoPosition> BuildGeoPosition <TOwner>(this OwnedNavigationBuilder <TOwner, GeoPosition> builder, string prefix = null)
            where TOwner : class
        {
            builder.Property(p => p.Latitude).HasColumnName($"{prefix}latitude").HasColumnType("decimal(11,8)");
            builder.Property(p => p.Longitude).HasColumnName($"{prefix}longitude").HasColumnType("decimal(11,8)");

            return(builder);
        }
        public static OwnedNavigationBuilder <TOwner, Weight> BuildWeight <TOwner>(this OwnedNavigationBuilder <TOwner, Weight> builder, string prefix = null, bool required = false)
            where TOwner : class
        {
            builder.Property(d => d.Value).HasColumnType("decimal(16,6)").HasColumnName($"{prefix}weight");
            builder.Property(d => d.Unit).IsUnicode(false).HasMaxLength(2).IsFixedLength().HasColumnName($"{prefix}weight_unit");
            builder.Property(d => d.Unit).HasConversion <string>();

            return(builder);
        }
        public static void Configure <TEntity>(OwnedNavigationBuilder <TEntity, SystemInfo> builder)
            where TEntity : Entity
        {
            builder.Property(x => x.Grade)
            .HasColumnType("decimal(18, 2)");

            builder.Property(x => x.UpdatedDate)
            .ValueGeneratedOnUpdate();
        }
예제 #8
0
        private static void ConfigureChangeFields(
            OwnedNavigationBuilder <ProductFieldChangedProductChangeNoteEntity, FieldChangedRecordEntity> builder)
        {
            builder.ToJsonProperty("changedFields");

            builder.Property(entity => entity.FieldName).ToJsonProperty("fieldName").IsRequired();
            builder.Property(entity => entity.PreviousValue).ToJsonProperty("previousValue").IsRequired();
            builder.Property(entity => entity.NewValue).ToJsonProperty("newValue").IsRequired();
        }
        public static OwnedNavigationBuilder <TOwner, Audit> BuildAudit <TOwner>(this OwnedNavigationBuilder <TOwner, Audit> builder)
            where TOwner : class
        {
            builder.Property(d => d.CreatedBy).IsUnicode(false).HasMaxLength(50).HasColumnName("created_by");
            builder.Property(d => d.ModifiedBy).IsUnicode(false).HasMaxLength(50).HasColumnName("modified_by");
            builder.Property(d => d.CreatedOn).HasColumnName("created_on");
            builder.Property(d => d.ModifiedOn).HasColumnName("modified_on");

            return(builder);
        }
예제 #10
0
        public static void Configure <TEntity>(OwnedNavigationBuilder <TEntity, Money> builder)
            where TEntity : Entity
        {
            builder.Property(x => x.Currency)
            .HasMaxLength(64)
            .IsRequired();

            builder.Property(x => x.Amount)
            .HasColumnType("decimal(18, 2)")
            .IsRequired();
        }
예제 #11
0
        public static void Configure <TEntity>(OwnedNavigationBuilder <TEntity, Invoice> builder)
            where TEntity : Entity
        {
            builder.Property(x => x.Name)
            .HasMaxLength(255);

            builder.Property(x => x.CreatedDate)
            .ValueGeneratedOnAdd();

            builder.Property(x => x.Content);
        }
        public static OwnedNavigationBuilder <TOwner, Dimensions> BuildDimensions <TOwner>(this OwnedNavigationBuilder <TOwner, Dimensions> builder, string prefix = null, bool required = false)
            where TOwner : class
        {
            builder.Property(d => d.Height).HasColumnType("decimal(16,6)").HasColumnName($"{prefix}height");
            builder.Property(d => d.Length).HasColumnType("decimal(16,6)").HasColumnName($"{prefix}length");
            builder.Property(d => d.Width).HasColumnType("decimal(16,6)").HasColumnName($"{prefix}width");
            builder.Property(d => d.Unit).IsUnicode(false).HasMaxLength(2).HasColumnName($"{prefix}dimension_unit");
            builder.Property(d => d.Unit).HasConversion <string>();

            return(builder);
        }
        public static OwnedNavigationBuilder <TOwner, Contact> BuildContact <TOwner>(this OwnedNavigationBuilder <TOwner, Contact> builder, string prefix = null, bool required = false)
            where TOwner : class
        {
            //builder.Property(p => p.Phones).IsSeparatorDelimited();
            //builder.Property(p => p.Emails).IsSeparatorDelimited();
            builder.Property(p => p.Name).HasColumnName($"{prefix}name").HasMaxLength(100).IsRequired(required);
            builder.Property(p => p.Phones).HasColumnName($"{prefix}phones").HasMaxLength(100);
            builder.Property(p => p.Emails).HasColumnName($"{prefix}emails").HasMaxLength(1024);

            return(builder);
        }
        public static OwnedNavigationBuilder <TOwner, StreetAddress> BuildStreetAddress <TOwner>(this OwnedNavigationBuilder <TOwner, StreetAddress> builder, string prefix = null, bool required = false)
            where TOwner : class
        {
            //builder.Property(p => p.Street).IsSeparatorDelimited();
            builder.Property(p => p.Country).HasColumnName($"{prefix}country").IsCode(2, required: required);
            builder.Property(p => p.City).HasColumnName($"{prefix}city").HasMaxLength(100).IsRequired(required);
            builder.Property(p => p.State).HasColumnName($"{prefix}state").HasMaxLength(100);
            builder.Property(p => p.PostCode).HasColumnName($"{prefix}post_code").HasMaxLength(20).IsUnicode(false);
            builder.Property(p => p.Street).HasColumnName($"{prefix}street").HasMaxLength(1024);

            return(builder);
        }
예제 #15
0
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
        internal static void Configure <N>(OwnedNavigationBuilder <N, ModRange> b) where N : class
        {
            b.Property(d => d.VersionRange)
            .HasConversion(
                v => v.ToString(),
                v => new Range(v, false));
        }
예제 #16
0
        /// <summary>
        /// Adds a converter for all properties derived from <see cref="TypeSafeEnum{TValue, TKey}"/> so that entity framework core
        /// can work with it.
        /// </summary>
        /// <param name="modelBuilder"></param>
        public static void ConfigureEnumExt(this ModelBuilder modelBuilder)
        {
            foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            {
                var properties = entityType.ClrType.GetProperties()
                                 .Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(TypeSafeEnum <,>)));

                foreach (var property in properties)
                {
                    var keyType = TypeUtil.GetKeyType(property.PropertyType, typeof(TypeSafeEnum <,>));

                    var converterType = typeof(TypeSafeEnumConverter <,>).MakeGenericType(property.PropertyType, keyType);

                    var converter = (ValueConverter)Activator.CreateInstance(converterType);

                    if (entityType.IsOwned())
                    {
#pragma warning disable EF1001 // Internal EF Core API usage, might change without notice -> have not found a better way till now
                        var navigationBuilder = new OwnedNavigationBuilder(entityType.FindOwnership());
#pragma warning restore EF1001

                        navigationBuilder.Property(property.Name).HasConversion(converter);
                    }
                    else
                    {
                        modelBuilder.Entity(entityType.Name).Property(property.Name).HasConversion(converter);
                    }
                }
            }
        }
        private void FileBuildAction(OwnedNavigationBuilder <Person, File?> b)
        {
            b.WithOwner(f => f.Owner);

            b.HasKey(f => f.Id);

            b.Property(f => f.Name)
            .HasMaxLength(StringLengths.Short);

            b.Property(f => f.FileUri)
            .HasConversion <string>()
            .HasMaxLength(StringLengths.Short);

            b.Property(f => f.MimeType)
            .HasMaxLength(StringLengths.VeryShort);
        }
예제 #18
0
 public static void HasVirtualPrimaryKey <TOwnerEntity, TRelatedEntity>(this OwnedNavigationBuilder <TOwnerEntity, TRelatedEntity> entityTypeBuilder)
     where TOwnerEntity : class
     where TRelatedEntity : class
 {
     entityTypeBuilder.HasKey("Id");
     entityTypeBuilder.Property("Id").HasColumnType("bigint");
 }
예제 #19
0
        protected virtual void Configure(OwnedNavigationBuilder <Level3, Level4> l4)
        {
            l4.Ignore(e => e.OneToOne_Optional_Self4)
            .Ignore(e => e.OneToMany_Required_Self4)
            .Ignore(e => e.OneToMany_Required_Self_Inverse4)
            .Ignore(e => e.OneToMany_Optional_Self4)
            .Ignore(e => e.OneToMany_Optional_Self_Inverse4);

            l4.Property(e => e.Id).ValueGeneratedNever();

            l4.HasOne(e => e.OneToOne_Optional_PK_Inverse4)
            .WithOne(e => e.OneToOne_Optional_PK3)
            .HasPrincipalKey <Level3>()
            .IsRequired(false);

            l4.HasOne(e => e.OneToOne_Required_FK_Inverse4)
            .WithOne(e => e.OneToOne_Required_FK3)
            .HasForeignKey <Level4>(e => e.Level3_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l4.HasOne(e => e.OneToOne_Optional_FK_Inverse4)
            .WithOne(e => e.OneToOne_Optional_FK3)
            .HasForeignKey <Level4>(e => e.Level3_Optional_Id)
            .IsRequired(false);

            l4.HasOne(e => e.OneToMany_Required_Inverse4)
            .WithMany(e => e.OneToMany_Required3)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l4.HasOne(e => e.OneToMany_Optional_Inverse4)
            .WithMany(e => e.OneToMany_Optional3)
            .IsRequired(false);
        }
        protected override void Configure(OwnedNavigationBuilder <Level1, Level2> l2)
        {
            base.Configure(l2);

            l2.ToTable(nameof(Level1));
            l2.Property(l => l.Date).HasColumnName("OneToOne_Required_PK_Date");
        }
예제 #21
0
        internal static void Configure(OwnedNavigationBuilder <SkillSnapshot, SkillReference> builder)
        {
            builder.ToTable(name: "SkillSnapshotSkillReferences");

            builder.WithOwner()
            .HasForeignKey("SkillSnapshotId");

            builder.Property(id => id.Id)
            .HasColumnName("SkillId")
            .ValueGeneratedNever();

            builder.Property(colour => colour.Colour)
            .HasColumnName("SkillColour");

            builder.HasKey("SkillSnapshotId", "Id");
        }
예제 #22
0
        public static void Configure <TEntity>(OwnedNavigationBuilder <TEntity, CustomerDetails> builder)
            where TEntity : Entity
        {
            builder.Property(x => x.Name)
            .HasMaxLength(64);

            builder.Property(x => x.Surname)
            .HasMaxLength(64);

            builder.Property(x => x.PhoneNumber)
            .HasMaxLength(64);

            builder.Property(x => x.Email)
            .HasMaxLength(64);

            builder.Property(x => x.Grade)
            .HasColumnType("decimal(18, 2)");
        }
 public static void ToJsonProperties <T, D>(this OwnedNavigationBuilder <T, D> builder)
     where T : class
     where D : class
 {
     builder.ToJsonProperty(FirstCharToLowerCase(builder.Metadata.GetNavigation(false).Name));
     foreach (var property in GetProperties(builder))
     {
         builder.Property(property.Name).ToJsonProperty(FirstCharToLowerCase(property.Name));
     }
 }
예제 #24
0
#pragma warning disable CS0618 // Type or member is obsolete
        private static void Build(EntityTypeBuilder builder1, OwnedNavigationBuilder builder2, AnnotatedProperty <DecimalAttribute> builderArg)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            var property = builder1?.Property(builderArg.Name) ?? builder2.Property(builderArg.Name);

            if (property == null)
            {
                throw new Exception($"Could not determind property \"{builderArg.Name}\" of \"{(builder2.OwnedEntityType as EntityType).Name}\"");
            }
            property.HasColumnType($"decimal({builderArg.Attribute.Precision}, {builderArg.Attribute.Scale})");
        }
예제 #25
0
        public void ConfigureSearch <TOwner, TOwned>(OwnedNavigationBuilder <TOwner, TOwned> accessor)
            where TOwner : BaseEntity
            where TOwned : BaseEntity, IOwnedEntity, ISearchableEntity
        {
            PropertyBuilder <NpgsqlTsVector> property = accessor
                                                        .Property <NpgsqlTsVector>(nameof(ISearchableEntity.SearchVector))
                                                        .IsGeneratedTsVectorColumn("english", GetSearchProperties().GetPropertyAccessList().Select(ReflectionExtensions.GetSimpleMemberName).ToArray());

            accessor
            .HasIndex(nameof(ISearchableEntity.SearchVector))
            .HasMethod("GIN");
        }
예제 #26
0
        private void TestEntityEntityTypeConfiguration(OwnedNavigationBuilder <TestAggregateRoot, TestEntity> builder)
        {
            builder.ConfigureEntity <TestAggregateRoot, TestEntity, Guid>();
            builder.ConfigureCreatedDate <TestAggregateRoot, TestEntity, Guid?>();
            builder.ConfigureUpdatedDate <TestAggregateRoot, TestEntity, Guid?>();
            builder.ConfigureDeactivatedDate <TestAggregateRoot, TestEntity, Guid?>();
            builder.ConfigureReactivatedDate <TestAggregateRoot, TestEntity, Guid?>();

            builder.Property(e => e.TestString)
            .IsRequired()
            .HasMaxLength(256);
        }
        protected virtual void Configure(OwnedNavigationBuilder <Level2, Level3> l3)
        {
            var level3 = l3.Ignore(e => e.OneToOne_Optional_Self3)
                         .Ignore(e => e.OneToMany_Required_Self3)
                         .Ignore(e => e.OneToMany_Required_Self_Inverse3)
                         .Ignore(e => e.OneToMany_Optional_Self3)
                         .Ignore(e => e.OneToMany_Optional_Self_Inverse3)
                         .OwnedEntityType;

            l3.Property(e => e.Id).ValueGeneratedNever();

            l3.HasOne(e => e.OneToOne_Optional_PK_Inverse3)
            .WithOne(e => e.OneToOne_Optional_PK2)
            .HasPrincipalKey <Level2>(e => e.Id)
            .IsRequired(false);

            l3.HasOne(e => e.OneToOne_Required_FK_Inverse3)
            .WithOne(e => e.OneToOne_Required_FK2)
            .HasForeignKey <Level3>(e => e.Level2_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l3.HasOne(e => e.OneToOne_Optional_FK_Inverse3)
            .WithOne(e => e.OneToOne_Optional_FK2)
            .HasForeignKey <Level3>(e => e.Level2_Optional_Id)
            .IsRequired(false);

            l3.HasOne(e => e.OneToMany_Required_Inverse3)
            .WithMany(e => e.OneToMany_Required2)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l3.HasOne(e => e.OneToMany_Optional_Inverse3)
            .WithMany(e => e.OneToMany_Optional2)
            .IsRequired(false);

            ForeignKey level4Fk;
            var        level4 = level3.Model.AddEntityType(
                "Level1.OneToOne_Required_PK1#Level2.OneToOne_Required_PK2#Level3.OneToOne_Required_PK3#Level4",
                typeof(Level4));

            using (var batch = ((Model)level3.Model).ConventionDispatcher.DelayConventions())
            {
                level4Fk          = (ForeignKey)level4.AddForeignKey(level4.FindProperty(nameof(Level4.Id)), level3.FindPrimaryKey(), level3);
                level4Fk.IsUnique = true;
                level4Fk.SetPrincipalToDependent(nameof(Level3.OneToOne_Required_PK3), ConfigurationSource.Explicit);
                level4Fk.SetDependentToPrincipal(nameof(Level4.OneToOne_Required_PK_Inverse4), ConfigurationSource.Explicit);
                level4Fk.DeleteBehavior = DeleteBehavior.Restrict;
                level4Fk = (ForeignKey)batch.Run(level4Fk);
            }

            Configure(new OwnedNavigationBuilder <Level3, Level4>(level4Fk));
        }
        public static void ConfigureAddress <TParentEntity>(this OwnedNavigationBuilder <TParentEntity, PostalAddress> a) where TParentEntity : class
        {
            a.WithOwner();

            a.Property(a => a.RecipientName)
            .HasMaxLength(255)
            .IsRequired();

            a.Property(a => a.ZipCode)
            .HasMaxLength(18)
            .IsRequired();

            a.Property(a => a.Street)
            .HasMaxLength(180)
            .IsRequired();

            a.Property(a => a.State)
            .HasMaxLength(60);

            a.Property(a => a.Country)
            .HasMaxLength(90)
            .IsRequired();

            a.Property(a => a.City)
            .HasMaxLength(100)
            .IsRequired();
        }
예제 #29
0
        protected virtual void Configure(OwnedNavigationBuilder <Level1, Level2> l2)
        {
            var level2 = l2.Ignore(e => e.OneToOne_Optional_Self2)
                         .Ignore(e => e.OneToMany_Required_Self2)
                         .Ignore(e => e.OneToMany_Required_Self_Inverse2)
                         .Ignore(e => e.OneToMany_Optional_Self2)
                         .Ignore(e => e.OneToMany_Optional_Self_Inverse2)
                         .OwnedEntityType;

            l2.Property(e => e.Id).ValueGeneratedNever();

            l2.HasOne(e => e.OneToOne_Optional_PK_Inverse2)
            .WithOne(e => e.OneToOne_Optional_PK1)
            .HasPrincipalKey <Level1>(e => e.Id)
            .IsRequired(false);

            l2.HasOne(e => e.OneToOne_Required_FK_Inverse2)
            .WithOne(e => e.OneToOne_Required_FK1)
            .HasForeignKey <Level2>(e => e.Level1_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l2.HasOne(e => e.OneToOne_Optional_FK_Inverse2)
            .WithOne(e => e.OneToOne_Optional_FK1)
            .HasForeignKey <Level2>(e => e.Level1_Optional_Id)
            .IsRequired(false);

            l2.HasOne(e => e.OneToMany_Required_Inverse2)
            .WithMany(e => e.OneToMany_Required1)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l2.HasOne(e => e.OneToMany_Optional_Inverse2)
            .WithMany(e => e.OneToMany_Optional1)
            .IsRequired(false);

            ForeignKey level3Fk;
            var        level3 = level2.Model.AddEntityType(typeof(Level3), nameof(Level2.OneToOne_Required_PK2), level2);

            using (var batch = ((Model)level2.Model).ConventionDispatcher.StartBatch())
            {
                level3Fk          = (ForeignKey)level3.AddForeignKey(level3.FindProperty(nameof(Level3.Id)), level2.FindPrimaryKey(), level2);
                level3Fk.IsUnique = true;
                level3Fk.HasPrincipalToDependent(nameof(Level2.OneToOne_Required_PK2), ConfigurationSource.Explicit);
                level3Fk.HasDependentToPrincipal(nameof(Level3.OneToOne_Required_PK_Inverse3), ConfigurationSource.Explicit);
                level3Fk.DeleteBehavior = DeleteBehavior.Restrict;
                level3Fk = batch.Run(level3Fk);
            }

            Configure(new OwnedNavigationBuilder <Level2, Level3>((EntityType)level2, level3Fk.DeclaringEntityType, level3Fk.Builder));
        }
예제 #30
0
 public static void Setup <T>(OwnedNavigationBuilder <T, Vehicle> entity) where T : class
 {
     entity.WithOwner();
     entity.Property(e => e.Displacement).IsRequired();
     entity.Property(e => e.Make).IsRequired();
     entity.Property(e => e.Model).IsRequired();
     entity.Property(e => e.Registration).IsRequired();
     entity.Property(e => e.Year).IsRequired();
     entity.Property(e => e.Induction).IsRequired();
 }