• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

MissingMemberException

I've created a custom class (contacts_list) that inherits all the properties from a Linq Class (tb_contacts) and implements an own property (my_field):

public partial class contacts_list : tb_contacts
{
      private bool _my_field;
      public bool my_field
      {
            get { return _my_field; }
            set { _my_field = value; }
      }
}


Well, I fill an EntitySet<contacts_list> and I link this EntitySet<contacts_list> to the datasource of a datagridview.
The grid is filled perfectly, but when I click on the header of one of its columns to sort the records, I get a "MissingMemberException": "Impossible to find the member contacts_list.xxx".
Where "xxx" is the name of the header-column clicked.
I can improve to this error just only declaring in my class "contacts_list" all the properties from "tb_contacts". So my class will be:

public partial class contacts_list : tb_contacts
{
      public string name { get; set; }
      public string surname { get; set; }
      public string email { get; set; }

      private bool _my_field;
      public bool my_field
      {
            get { return _my_field; }
            set { _my_field = value; }
      }
}

But... it's a nonsense?!?!?!? All the properties should be inherited (in fact the datagridview is well filled)... so, I don't understand the exception...
0
demiket
Asked:
demiket
  • 5
  • 4
1 Solution
 
Fernando SotoCommented:
Can you post the class tb_contacts ?
0
 
demiketAuthor Commented:
It's the automatic class created by LINQ from table tb_contact.

Here's the code, thank you.

[Table(Name="dbo.tb_contacts")]
public partial class tb_contacts : INotifyPropertyChanging, INotifyPropertyChanged
{
	private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
	
	private int _id_contact;
	private string _name;
	private string _surname;
	private string _email;
	
	#region Extensibility Method Definitions
	partial void OnLoaded();
	partial void OnValidate(System.Data.Linq.ChangeAction action);
	partial void OnCreated();
	partial void Onid_contactChanging(int value);
	partial void Onid_contactChanged();
	partial void OnnameChanging(string value);
	partial void OnnameChanged();
	partial void OnsurnameChanging(string value);
	partial void OnsurnameChanged();
	partial void OnemailChanging(string value);
	partial void OnemailChanged();
	#endregion
	
	public tb_contacts()
	{
		OnCreated();
	}
	
	[Column(Storage="_id_contact", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
	public int id_contact
	{
		get
		{
			return this._id_contact;
		}
		set
		{
			if ((this._id_contact != value))
			{
				this.Onid_contactChanging(value);
				this.SendPropertyChanging();
				this._id_contact = value;
				this.SendPropertyChanged("id_contact");
				this.Onid_contactChanged();
			}
		}
	}
	
	[Column(Storage="_name", DbType="NVarChar(255)")]
	public string name
	{
		get
		{
			return this._name;
		}
		set
		{
			if ((this._name != value))
			{
				this.OnnomeChanging(value);
				this.SendPropertyChanging();
				this._name = value;
				this.SendPropertyChanged("name");
				this.OnnameChanged();
			}
		}
	}
	
	[Column(Storage="_surname", DbType="NVarChar(255)")]
	public string surname
	{
		get
		{
			return this._surname;
		}
		set
		{
			if ((this._surname != value))
			{
				this.OnsurnameChanging(value);
				this.SendPropertyChanging();
				this._surname = value;
				this.SendPropertyChanged("surname");
				this.OnsurnameChanged();
			}
		}
	}
	
	[Column(Storage="_email", DbType="NVarChar(255)")]
	public string email
	{
		get
		{
			return this._email;
		}
		set
		{
			if ((this._email != value))
			{
				this.OnemailChanging(value);
				this.SendPropertyChanging();
				this._email = value;
				this.SendPropertyChanged("email");
				this.OnemailChanged();
			}
		}
	}
	
	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));
		}
	}
}

Open in new window

0
 
Fernando SotoCommented:
Can you post the code that does this, "Well, I fill an EntitySet<contacts_list> and I link this EntitySet<contacts_list> to the datasource of a datagridview."?

Also how do you create the elements of the EntitySet<contacts_list>?
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
demiketAuthor Commented:
This is an example: the situation is more complex.
This is the function ContactsList to obtain the EntitySet<contacts_list>: so I put my datagridview.datasource=ContactsList.
public EntitySet<contacts_list> ContactsList
{
	EntitySet<contacts_list> _contactsList = new EntitySet<contacts_list>();
	var query = 
		from a in datacontext1.tb_contacts
		select new contacts_list
		{
			id_contact = a.tb_contacts.id_contact,
			name = a.tb_contacts.name,
			surname = a.tb_contacts.surname,
			email = a.tb_contacts.email,
			my_field = false
		};
	_contactsList.AddRange(query);
	return _contactsList;
}

Open in new window

0
 
Fernando SotoCommented:
Hi demiket;

Try and return a List<contacts_list> rather then an EntitySet<contacts_list>. See code snippet.

Fernando
public List<contacts_list> ContactsList()
{
    List<contacts_list> _contactsList = new List<contacts_list>();
 
    var query = 
        from a in datacontext1.tb_contacts
        select new contacts_list
        {
            id_contact = a.id_contact,
            name = a.name,
            surname = a.surname,
            email = a.email,
            my_field = false
        };
    _contactsList.AddRange(query);
    return _contactsList;
}

Open in new window

0
 
demiketAuthor Commented:
A list is not sortable: so when I link the list to the datasource of a datagridview, I can't sort the datagridview by the headers of the columns...
0
 
Fernando SotoCommented:
Sorry I have looked at this and can not find an answer to why the public properties of the base class can not be accessed through contacts_list when assigned to the data source of the DataGridView, might be a bug?
0
 
demiketAuthor Commented:
Wonderful, grrrrrrrrrr...
Might be a Bug?!?!?!?
I have thought in a Bug, but I'm just a newbie in Linq and C# so I thought I was making some mistakes...
0
 
Fernando SotoCommented:
No, it does not look like you made a mistake. The rules of inheritances are that all public members of a base class is accessible from the derived class and therefore the DataSource should be able to access it as qwell. But the workaround you have posted does the trick and it is simple.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now