Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. project mvc in autentication.
  2. create class Persona , class AppDbContext in Models
  3. Class Persona.cs
  4. public class Persona
  5. {
  6. public int Id { get; set; }
  7. public string Nombre { get; set; }
  8. public DateTime Nacimiento { get; set; }
  9. public int Edad { get; set; }
  10. }
  11.  
  12. Class AppDbContext.cs
  13. public class AppDbContext : DbContext
  14. {
  15. public DbSet<Persona> Persona { get; set; } // crea la tabla
  16.  
  17. }
  18.  
  19. console nuget
  20. PM>enable-migrations
  21. --->se crea la clase configuration donde permite realizar configuraciones al crear la bd
  22. poner AutomaticMigrationsEnabled = TRUE
  23.  
  24. Migrations/Configuration.cs
  25.  
  26. internal sealed class Configuration : DbMigrationsConfiguration<EFMvc.Models.AppDbContext>
  27. {
  28. public Configuration()
  29. {
  30. AutomaticMigrationsEnabled = true;
  31. }
  32.  
  33. protected override void Seed(EFMvc.Models.AppDbContext context)
  34. {
  35. // This method will be called after migrating to the latest version.
  36.  
  37. // You can use the DbSet<T>.AddOrUpdate() helper extension method
  38. // to avoid creating duplicate seed data.
  39. }
  40. }
  41.  
  42. Crear la bd con el siguiente comando en la consola nuget
  43. PM>update-database
  44. -->crea bd con la tabla Persona y sus propiedades que se establecieron en la clase Persona.cs
  45. -->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
  46.  
  47. Visualizar la bd creada
  48. Ver/Explorador de objetos de SQL Server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement