Database Reference
In-Depth Information
Figure 12-3. The model with the Donation entity
Listing 12-3. Code to Implement Logging of Open and Close of a Database Connection
class Program
{
static void Main(string[] args)
{
RunExample();
}
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
context.Donations.Add(new Donation
{
DonorName = "Robert Byrd",
Amount = 350M
});
context.Donations.Add(new Donation
{
DonorName = "Nancy McVoid",
Amount = 250M
});
context.Donations.Add(new Donation
{
DonorName = "Kim Kerns",
Amount = 750M
});
Console.WriteLine("About to SaveChanges()");
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
var list = context.Donations.Where(o => o.Amount > 300M);
Console.WriteLine("Donations over $300");
foreach (var donor in list)
Search WWH ::




Custom Search