Need 99-level help with Linq 2 Sql RRS feed

  • Question

  • I created a console app, added the new item "LINQ to SQL classes", and dragged the single table Northwind\Customer from Server Explorer to the design pane. (The dbml file is shown below).  I'm trying to use the code below to iterate over the Customer table but am lost.  In the "var CustQuery" statement VS complains that it "Could not find an implementation of the Query pattern for the source type ConsoleApplication1. Customer."  What? Any help much appreciated.


    using System;

    using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataClasses1DataContext db = new DataClasses1DataContext(); var CustQuery = from cust in Customer select cust; foreach (Customer cust in CustQuery) { Console.WriteLine("{0}", cust.City); } } } }


    Sunday, August 11, 2013 10:26 PM


  • I would have written:

               var CustQuery =
                    from cust in db.Customers
                    select cust;

    from cust in db.Customers, not from cust in Customer

    Customer is just the class name.  db.Customers is an accessor for the Customer table entity which basically does db.GetTable<Customer>()

    • Marked as answer by edm2 Tuesday, August 13, 2013 5:59 AM
    Monday, August 12, 2013 4:12 PM