0

I have a question, having simple context:

 public DbSet<Current> Currents { get; set; } public DbSet<Event> Events { get; set; } public DbSet<ApplicationFile> ApplicationFile { get; set; } private readonly string dbPath; public SqliteContext(string filePath) { dbPath = filePath; } public SqliteContext() { dbPath = $@"{AppDomain.CurrentDomain.BaseDirectory}\application.db"; ApplicationFileMigration(); } private void ApplicationFileMigration() { Database.EnsureCreated(); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite($@"Data Source={dbPath}"); } 

I want to create migration only on ApplicationFile entity and ignore Currents and Events, I know it is possible to do it with separate context, but is it possible in a single context, some kind of ignore annotation or default configuration?

3
  • Can you explain why you want to do that... there might be a better way to approach the actual problem. Commented Jan 23, 2018 at 8:36
  • 2 of those are imported sqlite files and do not need to be migrated, Application file is a internal db that i want to create for application purposes Commented Jan 23, 2018 at 8:37
  • Re-reading your comment, it sounds like the two pre-existing files would need a different connection string? Then my answer would be wrong, I assumed you work on one DB and you just have pre-existing tables. Commented Jan 23, 2018 at 11:52

1 Answer 1

1

Read the following: Entity Framework Code First Migrations with an existing database

The standard way to work with migrations would be, to first create your context only with the existing model. Then add a migration where actual changes are ignored (as per step 3 in linked article)

Add-Migration InitialCreate –IgnoreChanges Update-Database 

This will create the migration history table and will mark the current model as mapped.

Then add the additional entities that you really want to migrate as your second migration.

So in your case, first remove ApplicationFile for the initial migration, then re-add it and create a second migration. It will only create the DDL SQL for ApplicationFile, not for the other entities

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.