Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to work with existing and non existing tables with Entity code first

$
0
0

just reading a article on EF from this url https://www.codeproject.com/Tips/661053/Entity-Framework-Code-First-Map

normally EF code first create table when we migrate but say when we are working with existing tables then we need to give some special info to EF like this way

Database.SetInitializer<MyClassContext>(null);

public partial class MyClassContext : DbContext
    {
        static MyClassContext()
        {
            Database.SetInitializer<MyClassContext>(null);
        }

        public MyClassContext()
            : base("Name=MyClassContext")
        {
        }

        public DbSet<ClassAll> ClassAlls { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new ClassAllMap());
        }
    }

suppose i am in a scenario where i am working with existing table but also like to create some table from EF code to db. so tell me how could i migrate and create new tables in db when used this code Database.SetInitializer<MyClassContext>(null);

can i give instruction at table level which clearly indicate which table is existing and which does not. so when we migrate then only script will be generated for non existing tables.

please guide me.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>