0

I don't know whether to following is possible however I'd like to hear other opinions.

I have an existing database. I will use only certain number of tables and certain columns of those tables. To do that first I created classes and created specific mappings between these classes and database tables. Then implemented DbContext... so far I don't have any problem.

In the second part of the project there are classes which might not exist in the database. So when I run the project if they don't exist I want to implement those, like a normal codefirst implementation however I shouldn't touch other tables in the database.

Any thoughts?

Best

1 Answer 1

1
 In the second part of the project there are classes which might not exist in the database. So when I run the project if they don't exist I want to implement those, like a normal code first implementation however I shouldn't touch other tables in the database

use Ignore property in your dbcontext, overriding modelbuilder property

modelBuilder.Entity<YourClass>().Ignore(); 

This will not hamper your database if this class is not mapped in database. Hope this helps.

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

2 Comments

Thank you for your response. However what Ignore() does is not enough by itself. I need something like : if (thisTableDoesNotExist) then createTheTable
"if (thisTableDoesNotExist) then createTheTable " you can easily achieve is by migration. See this for detailed information msdn.microsoft.com/en-us/data/jj591621.aspx I hope this helps. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.