i am getting error like this.
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
here is my code
namespace EFfistSample
{
class Program
{
static void Main(string[] args)
{
var person = new Person { FirstName = "Sreekanth", LastName = "Vankamamidi", BirthDate = DateTime.Now };
using (var context = new MyContext())
{
context.Persons.Add(person);
context.SaveChanges();
}
Console.Write("Person Saved");
Console.ReadLine();
}
}
}
person.cs
namespace EFfistSample
{
public class Person
{
public int PersonID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public DateTime BirthDate { get; set; }
}
}
mycontext.cs
namespace EFfistSample
{
public class MyContext : DbContext
{
public MyContext()
{ }
public DbSet<Person> Persons { get; set; }
}
}
app.config i have given like this.
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
<add name="MyContext" connectionString="Data Source=(local); Initial Catalog=mydb; Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
please help me
thank you.