简体   繁体   English

由实体框架自动创建的数据库的位置

[英]The location of a database which is created by entity framework automatically

I have been using Entity framework recently and my WPF application totally works fine although i have a little problem. 我最近一直在使用Entity Framework,尽管有一些问题,我的WPF应用程序仍能正常工作。 Despite it stores and retrieves data, i can not see or find the data base which has been created by the framework. 尽管它存储和检索数据,但我看不到或找不到该框架创建的数据库。 When i start SqlServer management studio there is no new data base there. 当我启动SqlServer Management Studio时,那里没有新的数据库。 I also searched this path "C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL\\DATA" but i couldn't find it. 我也搜索了此路径“ C:\\ Program Files \\ Microsoft SQL Server \\ MSSQL10_50.MSSQLSERVER \\ MSSQL \\ DATA”,但找不到。 Another odd thing is that i didn't put any connection string inside the config file but as i said, it stores data somewhere in an anonymous data base. 另一个奇怪的是,我没有在配置文件中放入任何连接字符串,但是正如我所说的,它将数据存储在匿名数据库中的某个位置。 Would you mind telling me where exactly the data base is ? 您介意告诉我数据库到底在哪里吗? I am using Microsoft Sql Server 2008R2. 我正在使用Microsoft Sql Server 2008R2。

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

Work with connection string in web.config. 使用web.config中的连接字符串
Example: 例:

Web.config Web.config

  <connectionStrings>
    <add name="AnyName" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb);Initial Catalog=DbName;Integrated Security=True;MultipleActiveResultSets=True" />
  </connectionStrings>

In your context 根据您的情况

public Context()
        : base("AnyName")
    {}

The name ( "AnyName" ) must be the same in context and connectionstring. 名称( “ AnyName” )在上下文和连接字符串中必须相同。

Hope it's useful! 希望它有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM