none
'Select' not found. RRS feed

  • Question

  • Hello,

    Trying Linq To Sql for the first time.

    I added a "LINQ to SQL" class to my exercice project.
    I dragged and dropped my 'opComSilo' table on the O/R designer.
    This 'opComSilo' table is located on a Sql Server 2005 database.
    The server doesn't use IIS.
    I then tried to test a LINQ statement.
    The short program doesn't compile since this statement:

           var qry = from silo in opComSilo select silo

    produces an error on the underlined word.
    Here is the error message:

           Could not find an implementation of the query pattern for source type 'ConsoleApplication1.opComSilo'.
           'Select' not found.

    I found this message is often discussed on the web, but I could not find a solution to my problem.
    Given that this is a beginner exercice, I have good hopes that you could give me some useful suggestions.

    Thanks,

    Michel

    Monday, May 31, 2010 11:41 AM

Answers

  • Hi Michel,

    When you dropped your opComSilo table into the O/R designer, it created an object which inherits from DataContext (usually called DataClassesDataContext or similar).  You need to create a new DataContextDataClasses object and use that in your query.

    DataClassesDataContext myContext;
    
    using (myContext = new DataClassesDataContext())
    {
     var qry = from silo in myContext.opComSilo select silo;
    }
    

     

    A couple of notes

    1) It is recommended (but not necessary) to put the assignment of myContext in a using because DataClassesDataContext is IDisposable and therefore automatically disposed at the end of the using.

    2) There are multiple constructors for DataClassesDataContext; the parameterless one will take a value from your App.Config which was saved when using O/R Designer.

     

    • Proposed as answer by KristoferAEditor Monday, May 31, 2010 1:15 PM
    • Marked as answer by Lalbatros Monday, May 31, 2010 1:30 PM
    Monday, May 31, 2010 1:08 PM

All replies

  • Hi Michel,

    When you dropped your opComSilo table into the O/R designer, it created an object which inherits from DataContext (usually called DataClassesDataContext or similar).  You need to create a new DataContextDataClasses object and use that in your query.

    DataClassesDataContext myContext;
    
    using (myContext = new DataClassesDataContext())
    {
     var qry = from silo in myContext.opComSilo select silo;
    }
    

     

    A couple of notes

    1) It is recommended (but not necessary) to put the assignment of myContext in a using because DataClassesDataContext is IDisposable and therefore automatically disposed at the end of the using.

    2) There are multiple constructors for DataClassesDataContext; the parameterless one will take a value from your App.Config which was saved when using O/R Designer.

     

    • Proposed as answer by KristoferAEditor Monday, May 31, 2010 1:15 PM
    • Marked as answer by Lalbatros Monday, May 31, 2010 1:30 PM
    Monday, May 31, 2010 1:08 PM
  • p.s. depending on your pluralization settings, you might need to have myContext.opComSilos in your query. Intellisense should keep you right when typing the query.
    Monday, May 31, 2010 1:29 PM
  • Thanks a lot John,

    It worked immediately once I found the exact "DataClassesDataContext" name in the designer.cs listing.
    You made my day!

    Thanks,

    Michel

    • Marked as answer by Lalbatros Monday, May 31, 2010 1:30 PM
    • Unmarked as answer by Lalbatros Monday, May 31, 2010 1:30 PM
    Monday, May 31, 2010 1:29 PM