【发布时间】:2014-08-31 19:35:58
【问题描述】:
我在存储抽象类的属性时遇到了一些问题,构造函数似乎工作得很好。但是我无法将基本属性存储在我的子类数据库表中。
public abstract class Vehicle : IComparable< Vehicle >, IComparable {
public Int16 VehicleID;
public DateTime ProductionDate;
public Vehicle(Int16 _ Vehicle ID,DateTime _ProductionDate)
{
this.AccidentID = _ AccidentID;
this.ProductionDate = _ProductionDate;
}
int IComparable.CompareTo(object other) {
return CompareTo((Vehicle)other);
}
public int CompareTo(Vehicle other){
return this.ProductionDate.CompareTo(other.ProductionDate);
}
public Vehicle()
{}
}
public class Car : Vehicle
{
public Car ()
{
}
public Car (Int16 _VehicleID,DateTime _ProductionDate, Int16 _CarAttribute1, Int16 _CarAttribute2):base(_Vehicle ID,_ProductionDate)
{
this.AccidentID = _ AccidentID;
this.ProductionDate = _ProductionDate;
this.CarAttribute1 = _CarAttribute1
this.CarAttribute2 = _CarAttribute2
}
[PrimaryKey, AutoIncrement, Column("Attribute1")]
public Int16 CarAttribute1{ get; set;}
[Column("Attribute2")]
public Int16 CarAttribute2{ get; set;}
}
我对 C# 还很陌生,因此非常感谢一些指导 :) 我错过了什么?
【问题讨论】:
-
1.您使用哪个框架来处理 DB? 2. 你的代码有什么问题?数据库中的异常、错误或 NULL 数据?
-
嗨,我正在使用单声道和 Xamarin IDE,其中我使用了一个名为 SQLite.net async (nuget.org/packages/SQLite.Net.Async-PCL) 的组件,我的数据库列中的基类属性为空。
标签: c# database class inheritance abstract