Created
February 28, 2020 01:13
-
-
Save carloscds/47565a0bd42ead503848fdf2ad8e81d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using InjecaoDependenciaDiretaEF.Models; | |
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace InjecaoDependenciaDiretaEF.Data | |
{ | |
public class AplicacaoContext : DbContext | |
{ | |
public AplicacaoContext(DbContextOptions<AplicacaoContext> options) : base(options) | |
{ | |
SeedData(); | |
} | |
public DbSet<Cliente> Cliente { get; set; } | |
protected override void OnModelCreating(ModelBuilder builder) | |
{ | |
builder.Entity<Cliente>() | |
.Property(p => p.Id) | |
.IsRequired(); | |
builder.Entity<Cliente>() | |
.Property(p => p.Nome) | |
.HasMaxLength(100); | |
base.OnModelCreating(builder); | |
} | |
private void SeedData() | |
{ | |
Cliente.Add(new Models.Cliente { Nome = "Carlos", LimiteCredito = 1000 }); | |
Cliente.Add(new Models.Cliente { Nome = "Maria", LimiteCredito = 5000 }); | |
Cliente.Add(new Models.Cliente { Nome = "Jose", LimiteCredito = 500 }); | |
Cliente.Add(new Models.Cliente { Nome = "Joana", LimiteCredito = 600 }); | |
SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment