有人能告诉我在使用DataContext和LINQ to SQL时是否有从基类继承的方法?我有以下课程:
[Table(Name="names")]
public class person : IPerson, INotifyPropertyChanged
{
private int ID;
private string Fname;
private string Mname;
.....
[Column]
public string firstname
{
}
}
然后,我有继承的类:
public class child : person
{
private int isActive;
[Column]
public int isactive
{
}
public child(string firstname,...., int isactive):base(firstname,....)
{
}
}
我的数据访问类如下:
[Database]
public class dataxist : DataContext
{
public dataxist(string username, string servername, string pword,
string dbname) : base(@"uid=" + username + ";server=" + servername + ";pwd='" + pword + "'" +
";database=" + dbname + ";")
{
}
public Table<names> names;
}
当我尝试使用子类进行插入时,我在InsertOnSubmit()
调用时得到一个对象引用null错误,尽管我的子对象不是null
(注意:我正在传入对象然后检查类型以确定它是否是人或子对象然后转换为正确的对象:
databaseInfo.child c = (databaseInfo.child)n;
cd.names.InsertOnSubmit(c);
当我的子对象继承自person对象时,它是否还继承了[Table(Names="names")]
属性?或不?有什么建议吗?