[Mono-bugs] [Bug 536294] New: CS0120 for query comprehension expression

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Sep 2 10:54:36 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=536294


           Summary: CS0120 for query comprehension expression
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jpryor at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


The following block of code (which accesses no static members):

    var res = from cust in db.Customers
        where (from c in db.Customers
            where c.CompanyName == cust.CompanyName
            select c.CompanyName).Contains(cust.CompanyName)
    select cust.CompanyName;

Results in:

error CS0120: An object reference is required to access non-static member
`DbLinq.Mssql.Example.Program.<Main>c__AnonStorey1.cust'

Removing the nested 'where' allows it to compile (though it also changes
semantics, too, so it's not really a workaround, just narrows down where the
issue is).

To reproduce:

Save the sample code (below) and compile it:

    gmcs foo.cs -r:System.Data.dll -r:System.Data.Linq.dll

Expected results:

    No error.  (CSC compiles with no error.)

Actual results:

    Error CS0120 (see above).

Example code:

    using System;
    using System.Data.Linq.Mapping;
    using System.Data.Linq;
    using System.Data.SqlClient;
    using System.Linq;

    using nwind;

    namespace nwind
    {
        using System.Data.Linq.Mapping;
        using System.Data;
        using System.Collections.Generic;
        using System.Reflection;
        using System.Linq;
        using System.Linq.Expressions;
        using System.ComponentModel;
        using System;

        public partial class Northwind : DataContext
        {
            public Northwind(System.Data.IDbConnection connection)
                : base(connection)
            {
            }

            public Table<Customer> Customers
            {
                get
                {
                    return this.GetTable<Customer>();
                }
            }
        }

        [Table(Name = "dbo.Customers")]
        public partial class Customer : INotifyPropertyChanging,
INotifyPropertyChanged
        {

            private static PropertyChangingEventArgs emptyChangingEventArgs =
new PropertyChangingEventArgs(String.Empty);

            private string _CompanyName;

            #region Extensibility Method Definitions
            partial void OnCreated();
            partial void OnCompanyNameChanging(string value);
            partial void OnCompanyNameChanged();
            #endregion

            public Customer()
            {
                OnCreated();
            }

            [Column(Storage = "_CompanyName", DbType = "VarChar(40) NOT NULL",
CanBeNull = false)]
            public string CompanyName
            {
                get
                {
                    return this._CompanyName;
                }
                set
                {
                    if ((this._CompanyName != value))
                    {
                        this.OnCompanyNameChanging(value);
                        this.SendPropertyChanging();
                        this._CompanyName = value;
                        this.SendPropertyChanged("CompanyName");
                        this.OnCompanyNameChanged();
                    }
                }
            }

            public event PropertyChangingEventHandler PropertyChanging;

            public event PropertyChangedEventHandler PropertyChanged;

            protected virtual void SendPropertyChanging()
            {
                if ((this.PropertyChanging != null))
                {
                    this.PropertyChanging(this, emptyChangingEventArgs);
                }
            }

            protected virtual void SendPropertyChanged(String propertyName)
            {
                if ((this.PropertyChanged != null))
                {
                    this.PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }

    namespace DbLinq.Mssql.Example
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connStr = "Data Source=.\\SQLExpress;Integrated
Security=True;Initial Catalog=Northwind";
                 Northwind db = new Northwind(new SqlConnection(connStr));


                var res = from cust in db.Customers
                    where (from c in db.Customers
                            where c.CompanyName == cust.CompanyName
                            select c.CompanyName).Contains(cust.CompanyName)
                          select cust.CompanyName;


                foreach (var r in res.ToList())
                    Console.WriteLine(r);
            }
        }
    }

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list