1.第一步,创建实体类。

namespace MyMusicStore.Entities
{
    /// <summary>
    /// Song
    /// </summary>
    public class Song
    {
        public int id { get; set; }
        public string name { get; set; }
        public string address { get; set; }
        public string singer { get; set; }
        public string age { get; set; }
        public string type { get; set; }
        public string datatype { get; set; }
        public string length { get; set; }
    }
}

  2.创建Context上下文:

namespace MyMusicStore.Context
{
    /// <summary>
    /// Context Class
    /// </summary>
   public class MusicContext:DbContext
    {
       public DbSet<Song> songs { get; set; }
    }
}

  3.设置数据库连接字符串

<connectionStrings>
    <add name="MusicContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyMusicStore;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MyMusicStore.UI-20130227200923.mdf" />
  </connectionStrings>

  4.数据库数据初始化

 

相关文章:

  • 2021-09-16
  • 2021-10-12
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-11-09
相关资源
相似解决方案