Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- project mvc in autentication.
- create class Persona , class AppDbContext in Models
- Class Persona.cs
- public class Persona
- {
- public int Id { get; set; }
- public string Nombre { get; set; }
- public DateTime Nacimiento { get; set; }
- public int Edad { get; set; }
- }
- Class AppDbContext.cs
- public class AppDbContext : DbContext
- {
- public DbSet<Persona> Persona { get; set; } // crea la tabla
- }
- console nuget
- PM>enable-migrations
- --->se crea la clase configuration donde permite realizar configuraciones al crear la bd
- poner AutomaticMigrationsEnabled = TRUE
- Migrations/Configuration.cs
- internal sealed class Configuration : DbMigrationsConfiguration<EFMvc.Models.AppDbContext>
- {
- public Configuration()
- {
- AutomaticMigrationsEnabled = true;
- }
- protected override void Seed(EFMvc.Models.AppDbContext context)
- {
- // This method will be called after migrating to the latest version.
- // You can use the DbSet<T>.AddOrUpdate() helper extension method
- // to avoid creating duplicate seed data.
- }
- }
- Crear la bd con el siguiente comando en la consola nuget
- PM>update-database
- -->crea bd con la tabla Persona y sus propiedades que se establecieron en la clase Persona.cs
- -->si queremos agregar otra propiedad en la clase Persona y q se visualice en la bd/table solo hay que correr el comando update-datase
- Visualizar la bd creada
- Ver/Explorador de objetos de SQL Server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement