rkmorgan
rkmorgan

Reputation: 517

code first and existing database mixture

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

Upvotes: 0

Views: 62

Answers (1)

MKMohanty
MKMohanty

Reputation: 966

 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.

Upvotes: 1

Related Questions