Ejemplo n.º 1
0
        public void Configure(EntityTypeBuilder <Order> builder)
        {
            IMutableNavigation navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);

            builder.OwnsOne(o => o.ShipToAddress, a =>
            {
                a.WithOwner();

                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(180)
                .IsRequired();
            });
        }
        private void MemberInfoTest(
            IMutableNavigation navigation, PropertyAccessMode?accessMode, string forConstruction, string forSet, string forGet)
        {
            navigation.SetPropertyAccessMode(accessMode);

            MemberInfoTestCommon(navigation, accessMode, forConstruction, forSet, forGet);
        }
        private void RunConvention(IMutableNavigation navigation)
        {
            var context = new ConventionContext <IConventionNavigationBuilder>(
                ((ForeignKey)navigation.ForeignKey).DeclaringEntityType.Model.ConventionDispatcher);

            new BackingFieldConvention(CreateDependencies())
            .ProcessNavigationAdded(((IConventionNavigation)navigation).Builder, context);
        }
Ejemplo n.º 4
0
        private void RunConvention(IMutableNavigation navigation)
        {
            var foreignKey = navigation.ForeignKey;
            var context    = new ConventionContext <IConventionNavigation>(
                ((ForeignKey)foreignKey).DeclaringEntityType.Model.ConventionDispatcher);

            new BackingFieldConvention(new TestLogger <DbLoggerCategory.Model, TestLoggingDefinitions>())
            .ProcessNavigationAdded(((ForeignKey)foreignKey).Builder, (Navigation)navigation, context);
        }
Ejemplo n.º 5
0
        public void Configure(EntityTypeBuilder <Basket> builder)
        {
            IMutableNavigation navigation = builder.Metadata.FindNavigation(nameof(Basket.BasketItems));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);

            builder.Property(b => b.BuyerId)
            .IsRequired()
            .HasMaxLength(40);
        }
Ejemplo n.º 6
0
        public override void Configure(EntityTypeBuilder <Quotation> builder)
        {
            base.Configure(builder);

            builder.Property(q => q.Name)
            .HasMaxLength(180)
            .IsRequired();

            IMutableNavigation navigation = builder.Metadata.FindNavigation(nameof(Quotation.QuotationItems));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Ejemplo n.º 7
0
        public void Configure(EntityTypeBuilder <Warehouse> builder)
        {
            builder.HasKey(w => w.Id);

            builder.Property(w => w.Id)
            .ValueGeneratedOnAdd();

            builder.Property(w => w.Name)
            .HasMaxLength(180)
            .IsRequired();

            IMutableNavigation navigation = builder.Metadata.FindNavigation(nameof(Warehouse.Bins));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Ejemplo n.º 8
0
        public void Configure(EntityTypeBuilder <Poll> pollConfiguration)
        {
            pollConfiguration.ToTable("Polls", CleanArchitectureDbContext.DEFAULT_SCHEMA);

            pollConfiguration.HasKey(poll => poll.Id);

            pollConfiguration.Property(poll => poll.Title)
            .IsRequired();

            pollConfiguration.HasMany(poll => poll.Options)
            .WithOne()
            .HasForeignKey("PollId")
            .OnDelete(DeleteBehavior.Cascade);

            // Set as field (New since EF 1.1) to access the Option collection property through its field
            IMutableNavigation navigation = pollConfiguration.Metadata.FindNavigation(nameof(Poll.Options));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Ejemplo n.º 9
0
        public override void Configure(EntityTypeBuilder <SalesInvoice> builder)
        {
            base.Configure(builder);

            builder.Property(si => si.Name)
            .HasMaxLength(180)
            .IsRequired();

            builder.Property(si => si.InvoiceNotes)
            .HasMaxLength(500);

            builder.OwnsOne(si => si.BillingAddress, a =>
            {
                a.WithOwner();

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

                a.Property(a => a.Street2)
                .HasMaxLength(180);

                a.Property(a => a.City)
                .HasMaxLength(100)
                .IsRequired();

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

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

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

            IMutableNavigation navigation = builder.Metadata.FindNavigation(nameof(SalesInvoice.SalesInvoiceItems));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        public void Configure(EntityTypeBuilder <Option> optionConfiguration)
        {
            optionConfiguration.ToTable("Options", CleanArchitectureDbContext.DEFAULT_SCHEMA);

            optionConfiguration.HasKey(option => option.Id);

            optionConfiguration.Property(option => option.Text)
            .IsRequired();

            optionConfiguration.Property <int>("PollId")
            .IsRequired();

            optionConfiguration.HasMany(option => option.Votes)
            .WithOne()
            .HasForeignKey("OptionId")
            .OnDelete(DeleteBehavior.Cascade);

            IMutableNavigation navigation = optionConfiguration.Metadata.FindNavigation(nameof(Option.Votes));

            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Ejemplo n.º 11
0
        public override void Configure(EntityTypeBuilder <CropProduction> builder)
        {
            base.Configure(builder);

            builder.Property(cp => cp.Name)
            .HasMaxLength(180)
            .IsRequired();

            builder.Property(cp => cp.ExpectedYield)
            .HasColumnType("decimal(18,2)");

            builder.Property(cp => cp.ActualYield)
            .HasColumnType("decimal(18,2)");

            IMutableNavigation cropProductionFieldNavigation = builder.Metadata.FindNavigation(nameof(CropProduction.CropProductionFields));

            cropProductionFieldNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);

            IMutableNavigation cropProductionVarietyNavigation = builder.Metadata.FindNavigation(nameof(CropProduction.CropProductionVarieties));

            cropProductionVarietyNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     Gets the entity type that a given navigation property will hold an instance of
 ///     (or hold instances of if it is a collection navigation).
 /// </summary>
 /// <param name="navigation"> The navigation property to find the target entity type of. </param>
 /// <returns> The target entity type. </returns>
 public static IMutableEntityType GetTargetType([NotNull] this IMutableNavigation navigation)
 => (IMutableEntityType)((INavigation)navigation).GetTargetType();
Ejemplo n.º 13
0
 /// <summary>
 ///     Gets the navigation property on the other end of the relationship. Returns null if
 ///     there is no navigation property defined on the other end of the relationship.
 /// </summary>
 /// <param name="navigation"> The navigation property to find the inverse of. </param>
 /// <returns>
 ///     The inverse navigation, or null if none is defined.
 /// </returns>
 public static IMutableNavigation FindInverse([NotNull] this IMutableNavigation navigation)
 => (IMutableNavigation)((INavigation)navigation).FindInverse();
Ejemplo n.º 14
0
        public NavigationBuilder([NotNull] IMutableNavigation navigation)
        {
            Check.NotNull(navigation, nameof(navigation));

            Builder = ((Navigation)navigation).Builder;
        }
Ejemplo n.º 15
0
 public static IMutableEntityType GetTargetType(this IMutableNavigation navigation)
 => navigation.TargetEntityType;
Ejemplo n.º 16
0
 public static IMutableNavigation?FindInverse(this IMutableNavigation navigation)
 => navigation.Inverse;
Ejemplo n.º 17
0
 public static IMutableNavigation FindInverse([NotNull] this IMutableNavigation navigation)
 => navigation.Inverse;
Ejemplo n.º 18
0
 /// <summary>
 ///     Sets a value indicating whether this navigation should be eager loaded by default.
 /// </summary>
 /// <param name="navigation"> The navigation property to set whether it should be eager loaded for. </param>
 /// <param name="eagerLoaded"> A value indicating whether this navigation should be eager loaded by default. </param>
 public static void SetIsEagerLoaded([NotNull] this IMutableNavigation navigation, bool?eagerLoaded)
 => navigation.AsNavigation().SetIsEagerLoaded(eagerLoaded, ConfigurationSource.Explicit);
        /// <summary>
        ///     Sets a value indicating whether this navigation should be eager loaded by default.
        /// </summary>
        /// <param name="navigation"> The navigation property to set whether it should be eager loaded for. </param>.
        /// <param name="eagerLoaded"> A value indicating whether this navigation should be eager loaded by default. </param>
        public static void SetIsEagerLoaded([NotNull] this IMutableNavigation navigation, bool?eagerLoaded)
        {
            Check.NotNull(navigation, nameof(navigation));

            navigation[CoreAnnotationNames.EagerLoaded] = eagerLoaded;
        }