Skip to content

Value Objects

Mehdi Hadeli edited this page Apr 26, 2023 · 24 revisions

Articles

Samples

        builder.HasIndex(x => x.PhoneNumber).IsUnique();
        builder.Property(x => x.PhoneNumber)
            .IsRequired(false)
            .HasMaxLength(EfConstants.Lenght.Tiny);
            .HasConversion(x => (string?)x, x => (PhoneNumber?)x);

        builder.OwnsOne(
            x => x.PhoneNumber,
            a =>
            {
                a.Property(p => p.Value)
                    .HasColumnName(nameof(Customer.PhoneNumber).Underscore())
                    .IsRequired(false)
                    .HasMaxLength(EfConstants.Lenght.Tiny);

                // supporting index on owned types:
                // https://github.com/dotnet/efcore/issues/11336
                // https://github.com/dotnet/efcore/issues/12637
                a.HasIndex(p => p.Value).IsUnique();
            });
Clone this wiki locally