作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 EF 代码优先创建了一个数据库,就像那里 http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx .但是当我通过 add()
向 db 输入数据时然后调用savechanges()
我在 SQL Server 数据库文件夹中没有看到新数据库,也没有异常(exception)。这样对吗?我在哪里可以找到我的数据库以及如何将它放在数据库文件夹中?
我使用以下代码:
public class Name
{
public long NameId { get; set; }
public string FullName { get; set; }
}
public class InfoContext : DbContext
{
public DbSet<Name> Names { get; set; }
}
var db = new InfoContext();
var Names = new Name
{
NameId = 1,
FullName = "test"
};
db.Names.Add(Name);
db.SaveChanges();
var test = db.Names.Find(1);//there I get correct value
<connectionStrings>
<add name="InfoName" providerName="System.Data.SqlClient"
connectionString="Server = .\MYINSTANCE; Initial Catalog=mydbname;" />
</connectionStrings>
最佳答案
根据您的意见,您需要修改 web.config
项目根目录中的文件(不是 Views
文件夹中的文件。您可以在其中添加如下部分:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source = .; Initial Catalog = ITSDB; Integrated Security = true" providerName="System.Data.SqlClient"/>
</connectionStrings>
public class SomeContext : DbContext
{
...
}
<connectionStrings>
<add name="SomeContext" connectionString="Data Source = .; Initial Catalog = ITSDB; Integrated Security = true" providerName="System.Data.SqlClient"/>
</connectionStrings>
关于entity-framework - 在 SQL Server Management Studio 中看不到 EF 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18279458/
我是一名优秀的程序员,十分优秀!