0

i created an ASP.NET MVC 4 project, everything is by default, how can i write some config and/or c# codes for creating my database using EF5-Code-First?

i find these three nodes in web.config(under configuration root node)

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

config sections:

<configSections>
 <!--Comment-->
   <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

connectionStrings node:

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\W2012STATIOIN;Initial Catalog=TeamMgmt;Integrated Security=SSPI; User ID=admin; Password = 123 " />
  </connectionStrings>
4
  • Create a migration. pm> Enable-Migrations pm> Add-Migration Init Commented Sep 6, 2013 at 13:06
  • 1
    Since you are using Code First, the database should be created automatically based on your entity classes. I think you are not asking the right question, either way, you wouldn't define/customize your database in your config file, you have to do it via models, fluent api, migrations, etc. Commented Sep 6, 2013 at 13:14
  • 1
    @SOfanatic - strictly speaking the database will only be created when an attempt to access the database is first run. Commented Sep 7, 2013 at 15:55
  • @SOfanatic exactly! it works fine now! and i just know a little bit of fluent api(seems like using this to map model to DB table right? or other things i dunt no yet). but why should migrations be used? Commented Sep 8, 2013 at 2:35

1 Answer 1

1

It sounds like you are using the standard MVC4 template. If you try and register as a user, a database will be created for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.