Prevent table generation for a specific entity in EF6

.net c# ef-migrations entity-framework entity-framework-6

Question

How can I prevent table creation for a certain object when my database context is created?

public class MyDbContext : DbContext {
    public DbSet<MyEntity> MyEntity{ get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        modelBuilder.Ignore<MyEntity>();
        base.OnModelCreating(modelBuilder);
    }
}

This code is helpful, however it entirely excludes the object, thus I still need to query it.

1
1
6/21/2016 11:58:09 AM

Accepted Answer

ZZZ_tmp
2
6/21/2016 12:36:38 PM

Popular Answer

Your object will be mapped to an existing table or view in your scenario.

modelBuilder.Entity<entityname>().ToTable("Tablename");

or using this kind of data annotation

[Table("tablename")] 
public class ClassName {
....
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow