zoukankan      html  css  js  c++  java
  • CodeFirst问题集会一

    1、同步数据库时这个要注释掉
    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]  这句话去掉注释

    编译运行程序时要注释掉,不然报错!

    /// <summary>
        /// 客户实体
        /// </summary>
        // [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
        public class CustomerEntities : DbContext, IRequest
        {
            static CustomerEntities()
            {
                DbInterception.Add(new EfIntercepter());
            }
            /// <summary>
            /// 仅用于数据迁移
            /// </summary>
            public CustomerEntities()
                : base("server=192.168.99.62;user=user_1;password=123;database=Customer.Service.Db;port=3306;Charset=utf8;")
            {
    
            }
    
            public CustomerEntities(DbConnection existingConnection)
            : base(existingConnection, true)
            {
    
            }
            public string RequestId { get; set; }
            public string FirstRequestId { get; set; }
            public string NodeName { get; set; }
            public int MvcUserId { get; set; }
    
            public DbSet<TCustomer> TCustomers { get; set; }
            public DbSet<TCustomerBusiness> TCustomerBusinesss { get; set; }
            public DbSet<TCustomerService> TCustomerServices { get; set; }
            public DbSet<TServiceType> TServiceTypes { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            }
    
        }
    

     2、改数据库的话要改文档,不能直接改库
    add-miguration  生成模型
    Update-Database -Force –TargetMigration: $InitialDatabase 强制删除
    Add-Migration -Force 强制重新建立添加库的cs文件

    每次改动先运行 add-miguration  再运行  Update-Database

  • 相关阅读:
    TypeError: 'ExcelData' object is not iterable
    输出重定向
    联想Thinkpad T450 屏幕更换记录
    C-sysytem命令的使用
    CMD命令大全
    Ubuntu16.04 添加 Docker用户组
    Docker学习
    Linux系统卡死后紧急处理
    Django之ModelForm详解
    Django的ORM实现数据库事务操作
  • 原文地址:https://www.cnblogs.com/demonyx/p/6857704.html
Copyright © 2011-2022 走看看