VS中安装官网教程, 新建EF Codefirst 工程是时, 会生成以下配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
从上面配置可以看出,不指定任何数据库的话, 默认是连接到localdb的, 那这个LocalDb在哪里?VS中怎么连接呢?
打开C:\Users\<USER NAME>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\
里面的文件夹名称就是你连接数据库的名称, 我的是mssqllocaldb
![](https://img.haomeiwen.com/i1431816/cb1e8b3efc4983c6.png)
在服务器资源管理器中新建连接到这个名称就可以了:
![](https://img.haomeiwen.com/i1431816/28217d6c09753ded.png)
网友评论