Dotnet
Articles Part 1

Solution - Modify Conduit Context Part 2

PRO
Outline

Solution: Modify Conduit Context Part 2

Modify the ConduitContext Class add the following properties
Visibility | Type                      | Name
------------------------------------------------------------------
  public   | DbSet<Editorial>    | Editorials
  public   | DbSet<Commentaries> | Commentaries
  public   | DbSet<Favorite>     | Favorites
  public   | DbSet<Tag>          | Tags

In the OnModelCreating Method, add the following code

Table configuration for Editorial
modelBuilder.Entity<Editorial>(entity =>
{
    entity.Property(e => e.CreatedAt)
            .HasColumnType("datetime")
            .HasDefaultValueSql("(getutcdate())");

    entity.Property(e => e.UpdatedAt)
            .HasColumnType("datetime")
            .HasDefaultValueSql("(getutcdate())");

    entity.HasOne(d => d.Person)
            .WithMany(p => p.Editorials)
            .HasForeignKey(d => d.PersonId)
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_Articles_People");
});
 

I finished! On to the next chapter