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?
Add your context class that inherits from DbContext
Declare your DbSet Customers {get;set;}
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.
发布评论
评论(1)
是的,但请注意,如果您的数据库不存在,就会发生这种情况。
请参阅http: //weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
声明您的 DbSet Customers {get;set;}
请注意有关数据库创建的重要部分:
“如果您的连接字符串指向磁盘上尚不存在的 SQL CE 或 SQL Express 数据库文件,则默认情况下会发生这种情况。您无需采取任何手动步骤即可发生这种情况。”
因此,以这种方式添加到现有数据库是不会发生的。
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
Declare your DbSet Customers {get;set;}
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.