CodeFirst问题集会一

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// <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

posted @   严于律己,宽以待人  阅读(293)  评论(3编辑  收藏  举报
点击右上角即可分享
微信分享提示