I am learning Fluent NHibernate and this issue arose from that project.
I have a base Class and a base Interface:
public abstract class Base : IBase
{
public virtual Guid Id { get; set; }
public virtual bool IsValid()
{
return false;
}
}
public interface IBase
{
Guid Id { get; set; }
bool IsValid();
}
which I inherit all of my other Domain classes from:
public class Item:Base, IItem
{
public virtual string Name { get; set; }
public override bool IsValid()
{
<snip>
}
<snip>
}
public interface IItem: IBase
{
string Name { get; set; }
<snip>
}
However when I try and bind a list of all Items to a winforms Combobox I get an error.
var ds = from i in GetSession().Linq<IItem>() select i;
cmbItems.DataSource = ds.ToArray();
this.cmbItems.DisplayMember = "Name";
this.cmbItems.ValueMember = "Id";
I get an error:
Cannot bind to the new value member. Parameter name: value
I have figured out that this occurs because I am implementing IBase on IItem. If I modify IItem it works fine.
public interface IItem: IBase
{
Guid Id { get; set; }
string Name { get; set; }
<snip>
bool IsValid();
}
So beyond the practical, just make it work, am I doing interfaces correctly? Should I not have interfaces implement other interfaces? If I should have IItem implement IBase, is there a way to bind properly to a Winforms control?