Class

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MvcMusic.Models
{
    public class Album
    {
        public int AlbumID { get; set; }
        public virtual int GenreId { get; set; }
        public virtual int ArtistId { get; set; }
        public int Title { get; set; }
        public decimal Price { get; set; }
        public string AlbumArtUrl { get; set; }

        public virtual Artist Artist { get; set; }
        public virtual Genre Genre { get; set; }
    }

    public class Genre
    {
        public virtual int GenreId { get; set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        public virtual List<Album> Albums { get; set; }
    }


    public class Artist 
    {
        public virtual int ArtistId { get; set; }
        public virtual string Name { get; set; }
    }

    public class MusicStoreDB : DbContext
    {
        public DbSet<Album> Albums { get; set; }
        public DbSet<Genre> Genres { get; set; }
        public DbSet<Artist> Artists { get; set; }
    }
}
原文地址:https://www.cnblogs.com/MarchThree/p/3669845.html