Wad S03 - Orm
Wad S03 - Orm
➢ Due to the difference between the two different models, getting the data and
associations from objects into relational table structure and vice versa requires a lot
of tedious programming
modelBuilder.Entity<Employee>(entity =>
{
entity.ToTable("Employee");
entity.Property(e => e.Id).ValueGeneratedNever();
entity.Property(e => e.HireDate).HasColumnType("date");
entity.HasOne(d => d.Department) modelBuilder.Entity<Person>(entity =>
.WithMany(p => p.Employees) {
.HasForeignKey(d => d.DepartmentId) entity.ToTable("Person");
.HasConstraintName("FK_Employee_Department"); entity.Property(e => e.Birthdate).HasColumnType("date");
entity.Property(e => e.FirstName).HasMaxLength(100);
entity.HasOne(d => d.IdNavigation) entity.Property(e => e.Gender)
.WithOne(p => p.Employee) .HasMaxLength(1)
.HasForeignKey<Employee>(d => d.Id) .IsUnicode(false)
.OnDelete(DeleteBehavior.ClientSetNull) .IsFixedLength();
.HasConstraintName("FK_Employee_Person"); entity.Property(e => e.LastName).HasMaxLength(100);
}); });
OnModelCreatingPartial(modelBuilder);
dotnet ef migrations add InitialMigrations --project Or use the following statement from
..\Company.DataContext\Company.DataContext.csproj “Package Manager Console”:
--startup-project .\Company.Web.csproj add-migration InitialMigrations