Add restrictions in configuration and data annotations.
This commit is contained in:
parent
5b90fa1242
commit
e4b92dedef
@ -10,6 +10,11 @@ public class TeamConfiguration : IEntityTypeConfiguration<Team>
|
|||||||
{
|
{
|
||||||
builder.HasIndex(t => t.Name).IsUnique();
|
builder.HasIndex(t => t.Name).IsUnique();
|
||||||
|
|
||||||
|
// example composite key configuration.
|
||||||
|
// builder.HasIndex(λ => new { λ.CoachId, λ.LeagueId }).IsUnique();
|
||||||
|
|
||||||
|
builder.Property(λ => λ.Name).HasMaxLength(100).IsRequired();
|
||||||
|
|
||||||
builder.HasMany(m => m.HomeMatches) // A team has many home matches.
|
builder.HasMany(m => m.HomeMatches) // A team has many home matches.
|
||||||
.WithOne(m => m.HomeTeam) // Mapped to the HomeTeam property.
|
.WithOne(m => m.HomeTeam) // Mapped to the HomeTeam property.
|
||||||
.HasForeignKey(m => m.HomeTeamId)
|
.HasForeignKey(m => m.HomeTeamId)
|
||||||
|
|||||||
@ -37,6 +37,7 @@ namespace EntityFrameworkCore.Data.Migrations
|
|||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@ -277,6 +278,8 @@ namespace EntityFrameworkCore.Data.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@ -429,6 +432,19 @@ namespace EntityFrameworkCore.Data.Migrations
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LeagueName")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.ToTable((string)null);
|
||||||
|
|
||||||
|
b.ToView("vw_TeamsAndLeagues", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
|
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")
|
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
namespace EntityFrameworkCore.Domain;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace EntityFrameworkCore.Domain;
|
||||||
// Since C#11, you do not need to wrap in accolades anymore.
|
// Since C#11, you do not need to wrap in accolades anymore.
|
||||||
public class Coach : BaseDomainModel
|
public class Coach : BaseDomainModel
|
||||||
{
|
{
|
||||||
|
[MaxLength(100)]
|
||||||
|
[Required]
|
||||||
public string Name { get; set; } // Strings are automatically become VARCHAR database types.
|
public string Name { get; set; } // Strings are automatically become VARCHAR database types.
|
||||||
public Team? Team { get; set; }
|
public Team? Team { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user