Skip to content

Instantly share code, notes, and snippets.

@gbelot2003
Created January 15, 2018 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbelot2003/ac4bb12aa3d0b931d39283d39faca697 to your computer and use it in GitHub Desktop.
Save gbelot2003/ac4bb12aa3d0b931d39283d39faca697 to your computer and use it in GitHub Desktop.
Code Fists EF context and models one to many
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