Home

Cannot access non-static member of outer type 'LINQPad.User.TypedDataContext'

The following error has stymied me.

Cannot access non-static member of outer type 'LINQPad.User.TypedDataContext' nested type 'UserQuery.MyOriginalClass'

What does this mean and how do I fix it?

Comments

  • edited February 2013
    Normally, anything types that you define end up as nested types, because LINQPad wraps everything that you enter into a class definition. You can tell LINQPad to extract the classes and define them as non-nested by adding the following to the beginning of your query:

    #define NONEST
  • Fixing the previous problem opened a new issue. I'm confident the query works in a live program. How do you query a database from a class method? The specific error that appears is 'Could not find an implementation of the query pattern for source type 'LINQPad.User.GenericTableName'. 'Select' not found.
    var query = from gtn in GenericTableName
    select sa.Asset.Name;
  • edited February 2013
    Is the method part of another class that you're writing? If so, you'll need to pass in the typed data context as follows:
        void Main()
        {
            Foo.Test (this);
        }
        
        class Foo
        {
            public static void Test (TypedDataContext data)
            {
                data.Customers.Dump();
            }
        }
    If the method isn't part of a separate class, just make sure it's an instance method and it will work just fine:
    
        void Main()
        {
            Test();
        }
        
        void Test()
        {
            Customers.Dump();
        }
Sign In or Register to comment.