Skip to content

CodeFirst

Marcin Sulecki edited this page Mar 15, 2017 · 4 revisions

Opis

  • Na podstawie klas generowana jest baza danych
  • Obsługuje klasy POCO (Plain Old CLR Objects)

Przewodnik

Utworzenie modelu

public class Artist : Base
    {
        public int ArtistId { get; set; }
        
        public string FirstName { get; set; }
 
        public string LastName { get; set; }
    }

public enum AlbumType
{
	LP,
	SG
}

public class Album : Base
   {
       public int AlbumId { get; set; }
 
       public string Title { get; set; }
 
       public decimal Price { get; set; }
 
       public Artist Artist { get; set; }

       public AlbumType AlbumType { get; set; }

   }

Utworzenie kontekstu

public class MusicStoreContext : DbContext
   {
       public DbSet<Artist> Artists { get; set; }
       public DbSet<Album> Albums { get; set; }
 
       public MusicStoreContext()
           : base("MusicStoreConnection")
       {
           
       }
   }
Clone this wiki locally