I’m looking for a way to indicate that a certain class is not to be used in the generation of the database (code-first web app) and not to be monitored for changes. In other words, I just want this specific class to be tottaly disconnected from any automatic persistence behavior (cause it will be used only as a DTO between View and Controller). Is it possible?
Share
Entity Framework uses the DbContext class which you are using to detect the expected structure of your database.
There are 2 ways that EF will assume an entity exists in your database.
DbSet<TEntity>(orIDbSet<TEntity>)When an entity is referenced it will expect that a table with that entities schema will exist in the database. You can play around with how the actual expected schema will look (names, ignored properties, required/not required ect) by either decorating the entity with attributes or by using the modelbuilder. My personal preference is to use the modelbuilder, take a look at my article here for examples of using the model builder for navigation properties.