Skip to content

Instantly share code, notes, and snippets.

@DannyRusnok
Created January 7, 2022 16:08
Show Gist options
  • Save DannyRusnok/450ac9c827f2038e7976d20481ce0300 to your computer and use it in GitHub Desktop.
Save DannyRusnok/450ac9c827f2038e7976d20481ce0300 to your computer and use it in GitHub Desktop.
Value Objects Article
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>(b =>
{
b.ToTable("Persons").HasKey(x => x.Id);
b.Property(x => x.Name).HasMaxLength(255).HasDefaultValue(string.Empty);
b.Property(x => x.LastName).HasMaxLength(255).HasDefaultValue(string.Empty);
b.OwnsOne(x => x.Address, sb =>
{
sb.Property(x => x.City).HasMaxLength(255).HasDefaultValue(string.Empty);
sb.Property(x => x.Street).HasMaxLength(255).HasDefaultValue(string.Empty);
sb.Property(x => x.ZipCode).HasMaxLength(255).HasDefaultValue(string.Empty);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment