23.3. Programming Against the Conceptual Model

Now you can author some code that interacts with your EDM. Begin by updating your Program class to call a helper method from Main(), which will print out each item in the Inventory database using your conceptual model, and another which will insert a new record to the Inventory table:

class Program
{
  static void Main(string[] args)
  {
    Console.WriteLine("***** Fun with ADO.NET EF *****");
    AddNewRecord();
    PrintAllInventory();
    Console.ReadLine();
  }

  private static void AddNewRecord()
  {
    // Add record to the Inventory table of the AutoLot
    // database.
    using (AutoLotEntities context = new AutoLotEntities())
    {
      try
      {
        // Hard code data for a new record, for testing. context.Cars.AddObject(new Car() { CarID ...

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.