I want to use code-first migrations to create the majority of my database, but I have a view that is preexisting (sourced from another database). I want to be able to access this view through my context/EF and join it with other tables, but obviously I don't need to create it. I've found a few things that seem to get me close, but I'm trying to follow best practices. I'm not overly familiar with the fluent API, but is this answer in there? Elsewhere?
Asked
Active
Viewed 55 times
0
-
Is your question about [relating views in code first](http://stackoverflow.com/questions/16890505/mapping-sql-view-in-code-first-approach) or simply preventing the view from being created in migrations? You can exclude it from migrations by doing an initial, no-op, migration: `add-migration InitialSnapshot -IgnoreChanges` – Steve Greene Jan 19 '17 at 19:30
-
The relating wasn't entirely part of my question, but it was floating around in the background, so thanks for pointing in a direction. With the no-op -- just add the class, do the add-migration -IgnoreChanges, then from that point forward, I can just add classes and migrations and only the new will be picked-up? – Josh Jan 19 '17 at 19:54
-
1Exactly. See here https://msdn.microsoft.com/en-us/data/dn579398.aspx#option1 – Steve Greene Jan 19 '17 at 20:24
-
Brilliant. I've read that page in the past, but didn't think about applying it to this situation. Thank you. – Josh Jan 19 '17 at 21:18