• .net core ef mysql 的使用


    第一步,安装运行环境

    PM> Install-Package Pomelo.EntityFrameworkCore.MySql

    PM> Install-Package Microsoft.EntityFrameworkCore.Tools –Pre

    Pomelo的链接已经在.NET CORE官方网站出现,是官方推荐的

    第二步,创建DBContext

    public class MyContext: DbContext
        {
            public DbSet<ts_weiba> ts_weibas { get; set; }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                => optionsBuilder
                    .UseMySql(@"server=127.0.0.1;uid=root;pwd=123456;database=coresns;charset=utf8;");
        }
    

      

    /// <summary>
        /// ts_weiba Entity Model
        /// </summary>    
        public class ts_weiba
        {
            /// <summary>
            /// 微吧ID
            /// </summary>
            [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
            public int weiba_id { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public int cid { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public string weiba_name { get; set; }
        
            /// <summary>
            /// 创建者ID
            /// </summary>
            public int uid { get; set; }
        
            /// <summary>
            /// 创建时间
            /// </summary>
            public int ctime { get; set; }
        
            /// <summary>
            /// 微吧logo
            /// </summary>
            public string logo { get; set; }
        
            /// <summary>
            /// 微吧简介
            /// </summary>
            public string intro { get; set; }
        
            /// <summary>
            /// 发帖权限 0-所有人 1-仅成员
            /// </summary>
            public int who_can_post { get; set; }
        
            /// <summary>
            /// 回帖权限 0-所有人 1-仅成员
            /// </summary>
            public int who_can_reply { get; set; }
        
            /// <summary>
            /// 成员数
            /// </summary>
            public int follower_count { get; set; }
        
            /// <summary>
            /// 帖子数
            /// </summary>
            public int thread_count { get; set; }
        
            /// <summary>
            /// 超级圈主uid
            /// </summary>
            public int admin_uid { get; set; }
        
            /// <summary>
            /// 是否设为推荐(热门)0-否,1-是
            /// </summary>
            public int recommend { get; set; }
        
            /// <summary>
            /// 是否通过审核:0-未通过,1-已通过
            /// </summary>
            public int status { get; set; }
        
            /// <summary>
            /// 是否删除 默认为0
            /// </summary>
            public int is_del { get; set; }
        
            /// <summary>
            /// 微吧公告
            /// </summary>
            public string notify { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public string avatar_big { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public string avatar_middle { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public int new_count { get; set; }
        
            /// <summary>
            /// 
            /// </summary>
            public DateTime new_day { get; set; }
        
            /// <summary>
            /// 申请附件信息
            /// </summary>
            public string info { get; set; }
        }
    

      

    第三步,生成数据库

    PM> Add-Migration t1

    PM> Update-Database -Verbose

  • 相关阅读:
    bzoj4598: [Sdoi2016]模式字符串
    bzoj3156: 防御准备
    bzoj1966: [Ahoi2005]VIRUS 病毒检测
    bzoj3170: [Tjoi2013]松鼠聚会
    bzoj3171: [Tjoi2013]循环格
    POJ1068Parencodings
    2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob
    POJ2632Crashing Robots
    POJ1328Radar Installation
    POJ2586Y2K Accounting Bug
  • 原文地址:https://www.cnblogs.com/nopassword/p/6285462.html
Copyright © 2020-2023  润新知