문제

Net MVC 3 web application. I generated my models from an existing database using "database first". But now, I would prefer to use the "code first" paradigm. Is that possible at all? How do I tell my solution that I want it to create tables for new models I code?

도움이 되었습니까?

해결책

Yes but be aware this happens if your database doesn't exist.

see http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

  1. Add your context class that inherits from DbContext Declare your DbSet Customers {get;set;}
  2. Add your connect string to your sdf file.

Note the important part regarding your database creation: "This happens by default if your connection-string points to either a SQL CE or SQL Express database file that does not already exist on disk. You do not need to take any manual steps for this to happen."

So to add to an existing database this way - isn't going to happen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top