Usage of existing database (not database first)

1. create class which is inheirt from DBContext, make sure there is an database connection which is named of xxxx

public class SimpleContext : DbContext
        {
            public SimpleContext() : base("name=xxxx")
            {
                Database.SetInitializer<SimpleContext>(null);
            }
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
            }

            public virtual DbSet<Product> Product{ get; set; }

        }

2. add mapped dataTable, schema and primary key

 

posted @ 2021-06-18 10:51  Kevin-xk  阅读(43)  评论(0)    收藏  举报