dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.62k stars 1.96k forks source link

[Bug] Fluent API to exclude a property. #1367

Closed Yuant-tobing closed 5 years ago

Yuant-tobing commented 5 years ago

DatabaseContext

modelBuilder.Entity<Province>(entity =>
{
    entity.HasKey(e => e.Iso)
        .HasName("PK_Province_Iso");

    entity.Ignore(e => e.CountryCodeNavigation);

    entity.Property(e => e.Iso)
        .HasMaxLength(4)
        .IsUnicode(false)
        .IsFixedLength()
        .ValueGeneratedNever();

    entity.Property(e => e.Name)
        .IsRequired()
        .HasMaxLength(80);

    entity.HasOne(e => e.CountryCodeNavigation)
        .WithMany(e => e.Provinces)
        .HasForeignKey(e => e.CountryCode)
        .HasConstraintName("FK_Province_Country_CountryCode")
        .OnDelete(DeleteBehavior.Restrict);
});

Migration data (Generated by command PMC "Add-Migration Initial")

migrationBuilder.CreateTable(
    name: "Provinces",
    columns: table => new
    {
        Iso = table.Column<string>(unicode: false, fixedLength: true, maxLength: 4, nullable: false),
        Name = table.Column<string>(maxLength: 80, nullable: false),
        CountryCode = table.Column<short>(nullable: false)
    },
    constraints: table =>
    {
        table.PrimaryKey("PK_Province_Iso", x => x.Iso);
        table.ForeignKey(
            name: "FK_Provinces_Countries_CountryCode",
            column: x => x.CountryCode,
            principalTable: "Countries",
            principalColumn: "Code",
            onDelete: ReferentialAction.Cascade);
    });

- EF Core 3 Preview 3 - Net Core 3 Preview 3.

This issue tracker is for documentation For product issues, use https://github.com/aspnet/EntityFramework/issues

ajcvickers commented 5 years ago

@Yuant-tobing See my comment here: https://github.com/aspnet/EntityFramework.Docs/issues/1135#issuecomment-475017735