Reputation: 28899
I would like to know that what should I write to create my database because on running of my application, still no database is created. I want to create local database in Visual Studio 2013.
Here is my context class
class dbContext : DbContext
{
public dbContext()
{
Database.SetInitializer<dbContext>(new DropCreateDatabaseIfModelChanges<dbContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
}
public DbSet<Employee> Employee { get; set; }
public DbSet<Credit> Credit { get; set; }
public DbSet<Debit> Debit { get; set; }
public DbSet<Salary> Salary { get; set; }
public DbSet<Category> Category { get; set; }
}
Here is Main-Class
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Database.SetInitializer<dbContext>(null);
}
private void btn_Click(object sender, RoutedEventArgs e)
{
try
{
dbContext context = new dbContext();
Category c = new Category();
c.Id = 1;
c.Name = "Category";
c.TotalExpenses = 0;
context.Category.Add(c);
context.SaveChanges();
btn.Content = context.Category.SingleOrDefault(x => x.Id == 1);
}
catch (Exception ex)
{
while (ex.InnerException != null)
{
ex = ex.InnerException;
MessageBox.Show(ex.Message);
}
MessageBox.Show(ex.Message);
}
}
}
Here is connectionString
<connectionStrings>
<add name="dbContext"
connectionString="server=.; database=sample; Integrated Security=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
when I try to save some values in database table which is still not created,
exception occurs "the provider did not return a ProviderManifestToken string"
What should I do to solve this.
Upvotes: 0
Views: 983
Reputation: 36
Change your connection string to this:
<connectionStrings>
<add name="dbContext"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=sample;Integrated Security=SSPI" providerName="System.Data.SqlClient""/>
Upvotes: 1