zoukankan      html  css  js  c++  java
  • .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

  • 相关阅读:
    阿里云OSS学习
    spring学习(十二)--spring中WebApplicationInitializer解析
    spring学习(十)--WebApplicationInitializer接口替代web.xml启动spring容器
    tomcat学习(二)--tomcat配置详解
    tomcat学习(一)--tomcat请求过程
    WEB工程中web.xml文件基本配置
    MAVEN学习(九)--利用nexus创建私服供上传下载jar包
    NGINX学习(九)--nginx配置示例
    Django所有ORM总结
    ORM一般操作
  • 原文地址:https://www.cnblogs.com/nopassword/p/6285462.html
Copyright © 2011-2022 走看看