I'm reading the book "Programming Entity Framework: DbContext", by Julia Lerman and Rowan Miller.
I've downloaded the "BAGA" solution from http://www.thedatafarm.com/learnentityframework/downloadfiles/dbcontext/StartingSolution.zip. I feel like a complete tool here because I can't get any of the code samples to run on my computer.
Normally, when I work with Entity Framework, I have a connection string in my configuration that tells Entity Framework what database to connect to and what credentials to use.
However, in this BAGA solution, I cannot find a connection string or a reference to a database anywhere in the solution. I'm guessing that the code is supposed to all run locally or somesuch, but when I type in and run any of the sample queries or updates, the computer pauses for about 20 seconds and then the following exception is thrown form the SaveChanges
method: "The provider did not return a ProviderManifestToken string".
I'm guessing that this solution is supposed to either use an internal database, or I'm supposed to type a connection string somewhere, but I don't see where in the book it tells me how to make this solution work.
It does clearly state that the solution uses EF Code First.
The console app code in BAGA looks like this:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using DataAccess;
using Model;
namespace BreakAwayConsole
{
class Program
{
static void Main(string[] args)
{
Database.SetInitializer(new InitializeBagaDatabaseWithSeedData());
// Call the latest example method here
// NOTE: Some examples will change data in the database. Ensure that you only call the
// latest example method. The InitializeBagaDatabaseWithSeedData database initializer
// (registered above) will take care of resetting the database before each run.
AddMachuPicchu();
}
// Add example methods here
private static void AddMachuPicchu()
{
using (var context = new BreakAwayContext())
{
var machuPicchu = new Destination
{
Name = "Machu Picchu",
Country = "Peru"
};
context.Destinations.Add(machuPicchu);
context.SaveChanges();
}
}
}
}
As @Wyktor Zychla asked, here is the code to BreakAwayContext.cs:
using System.Data.Entity;
using Model;
namespace DataAccess
{
public class BreakAwayContext : DbContext
{
public DbSet<Destination> Destinations { get; set; }
public DbSet<Lodging> Lodgings { get; set; }
public DbSet<Trip> Trips { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Reservation> Reservations { get; set; }
public DbSet<Payment> Payments { get; set; }
public DbSet<Activity> Activities { get; set; }
}
}
As you can see here, there is no constructor specified.