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

asked Feb 19, 2014 at 0:55

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.

answered Feb 19, 2014 at 9:10

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. ;)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.