Created
January 15, 2018 03:53
-
-
Save gbelot2003/ac4bb12aa3d0b931d39283d39faca697 to your computer and use it in GitHub Desktop.
Code Fists EF context and models one to many
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 System.Data.Entity; | |
namespace WebMigrationTest.Models | |
{ | |
public class Album | |
{ | |
[Key] public int AlmbumId { get; set; } | |
[Required()] | |
[StringLength(100, MinimumLength = 2)] | |
public string Title { get; set; } | |
public decimal Price { get; set; } | |
public int ArtistID { get; set; } | |
public virtual Artist Artist { get; set; } | |
} | |
public class Artist | |
{ | |
[Key] public int ArtistID { get; set; } | |
[Required()] | |
[StringLength(100, MinimumLength = 2)] | |
public String Title { get; set; } | |
public virtual List<Album> Albums { get; set; } | |
} | |
public class MusicContext : DbContext | |
{ | |
public DbSet<Album> Albums { get; set; } | |
public DbSet<Artist> Artists { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment