0
I’m new to Entity and I’m following a step by step to create a Code First application ( http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx ).
I created the application, debugged and it runs perfectly without any error, but no database is created... Follow the Main code and App.config:
I think it’s some configuration problem or something... Someone more experienced has an idea of what it might be?
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
Student stud = new Student() { StudentName = "New Student" };
try
{
ctx.Students.Add(stud);
ctx.SaveChanges();
}catch(Exception ex)
{
Console.WriteLine(ex);
}
}
}
<?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>
<connectionStrings>
<add name="entityFramework" connectionString="Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<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>
Thanks for the reply friend. I made the configuration but the database is not yet created when running...
– dev-john