1

I am using Migrations, but I had to manually add a SQL View as it pulls from other tables that aren't going to be mapped in my context/repository.

However, now it thinks the context has changed. I saw this answer that asks the same question, but it doesn't solve the problem. I can't just create the view model from existing entities.

Is there another way? I wouldn't mind using SqlQuery if I could something like:

context.Database.SqlQuery<ContactsByPartyCampaignViewModel>("myView")

Do I need to drop migrations?

Community
  • 1
  • 1
scojomodena
  • 842
  • 1
  • 14
  • 24

1 Answers1

0

Try this:

Add this : Database.SetInitializer<MyDbContext>(null);

in Global.asax under Application_Start() will solve your problem.

Vishal I P
  • 2,005
  • 4
  • 24
  • 41
  • Thanks, I am just using a console app and test project right now, so I don't have a global.asax file. I placed it in the modelbuilder override and that worked. It does this exactly do? It skips looking for migrations? When I run Add-Migration, it still picks it up. – scojomodena Mar 28 '14 at 18:13
  • Would be nice if you mentioned what this was actually doing so that others could make informed decisions on whether this was right for them. – BenjaminPaul Jan 20 '15 at 17:05
  • @BenjaminPaul :We use it to set the `DbInitialization` strategy go null as opposed to letting code first just use the default `“CreateDatabaseWhenNotExist”,` or using one of the others e.g. `“DropCreateDatabaseWhenModelChanges”` or even a custom strategy that you’ve created based on one of the built in strategies. You typically set `DbInitialization` strategies at application startup, for example in `global.asax` for web apps and you do the same even if you are setting it to null. – Vishal I P Jan 21 '15 at 13:04