none
EF code first RRS feed

  • Question

  • Hello

    I have such code:

    public class Blog
    {
        public int Id {get;set;}
    }
    
    public class Context : DbContext
    {
        public Blog Blogs {get;set;}
    }
    
    public static void Main()
    {
        var db = Context();
        Blog blog = new Blog { Id = 10};
        db.Blogs.Add(blog);
        db.SaveChanges();
    }

    I am using Visual Studio 2012. I have installed SQL Server 2012.
    And I want to know where is a table created? What is the path of created database?
    I didn't find created database in SQL Management Studio :(
    Help me, please.

    Sorry for my English.

    Saturday, October 12, 2013 11:53 PM

Answers

  • Hi. If you are using the default connection factory (you haven't set a connection string yourself) the database will have probably been created and hosted on LocalDB.

    Check the entityFramework section in your app/web.config and if it is set to LocalDbConnectionFactory this is the case.

     <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>

    The dataset files themselves will be under: C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\.

    To connect to LocalDB from SQL Management Studio enter (localdb)\V11.0 as the server name at the "Connect to Server logon".


    • Edited by JayChase Sunday, October 13, 2013 1:24 AM
    • Marked as answer by ArtsiomRusak Sunday, October 13, 2013 9:45 AM
    Sunday, October 13, 2013 1:16 AM

All replies

  • Hi. If you are using the default connection factory (you haven't set a connection string yourself) the database will have probably been created and hosted on LocalDB.

    Check the entityFramework section in your app/web.config and if it is set to LocalDbConnectionFactory this is the case.

     <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>

    The dataset files themselves will be under: C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\.

    To connect to LocalDB from SQL Management Studio enter (localdb)\V11.0 as the server name at the "Connect to Server logon".


    • Edited by JayChase Sunday, October 13, 2013 1:24 AM
    • Marked as answer by ArtsiomRusak Sunday, October 13, 2013 9:45 AM
    Sunday, October 13, 2013 1:16 AM
  • Hi. If you are using the default connection factory (you haven't set a connection string yourself) the database will have probably been created and hosted on LocalDB.

    Check the entityFramework section in your app/web.config and if it is set to LocalDbConnectionFactory this is the case.

     <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>

    The dataset files themselves will be under: C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\.

    To connect to LocalDB from SQL Management Studio enter (localdb)\V11.0 as the server name at the "Connect to Server logon".


    No, in my .config file I have such string:

    <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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    </configuration>


    Sunday, October 13, 2013 9:21 AM
  • I have found a solution. Thank you for prompt!
    Sunday, October 13, 2013 9:45 AM