MVC连接字符串code第一 [英] mvc connection string code first
问题描述
即时通讯新MVC的和IM尝试一些东西,用code第一。即时通讯目前有我的质数据库,问题每当我建我的应用程序编译成功完成,但我没有看到我的质数据库获得创建每当我检查我的本地服务器。不知道是否有什么东西我在想念着我的连接字符串。
im new to mvc and im trying out some stuff with code first. im currently having problems with my dbase, whenever i build my application the build finishes successfully but i dont see my dbase get created whenever i check my local server. was wondering if there's something im missing on my connection string.
<connectionStrings>
<add name="mydbase" connectionString="Data Source=localhost;Database=mydbase;Trusted_Connection=yes;" providerName="System.Data.SqlClient" />
</connectionStrings>
也许我应该看全局文件?我只是增加了一个初始化那里的种子,仅此而已,我没有看到任何理由为什么会混乱,起来......
or maybe i should be looking at the global file? i just added an initializer there for the seed and nothing more, i dont see any reason why that would mess that up...
在此先感谢!
推荐答案
数据库心不是承诺,直到你使用的范围与它有关。
The database isnt committed until you've used the Context to which it relates.
例如,在测试项目中,我打电话给我的初始化
For example, in a test project, I called my initializer
Database.SetInitializer<TestContext>(new TestContextInitializer());
和然后用于某些任务即上下文
and then used the context for some task i.e.
_testContext = new TestContext();
var stuff = from te in _testContext.TestTable select te;
这是在这一点上创建的数据库。
It's at this point the db is created.
这篇关于MVC连接字符串code第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!