C# 在子类db表中存储基本抽象类属性
我在存储抽象类的属性时遇到了一些问题,构造函数似乎工作得很好。但是,我无法在我的子类数据库表中存储基本属性C# 在子类db表中存储基本抽象类属性,c#,database,class,inheritance,abstract,C#,Database,Class,Inheritance,Abstract,我在存储抽象类的属性时遇到了一些问题,构造函数似乎工作得很好。但是,我无法在我的子类数据库表中存储基本属性 public abstract class Vehicle : IComparable< Vehicle >, IComparable { public Int16 VehicleID; public DateTime ProductionDate; public Vehicle(Int16 _ Vehicle ID,DateTime _Product
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;}
}
公共抽象类Vehicle:IComparable,IComparable{
公共Int16车辆ID;
公共日期时间生产日期;
公共车辆(Int16?车辆ID,日期时间?生产日期)
{
this.AccidentID=u AccidentID;
this.ProductionDate=\u ProductionDate;
}
int IComparable.CompareTo(对象其他){
将比较器返回到((车辆)其他);
}
公共内部比较(车辆其他){
返回此.ProductionDate.CompareTo(其他.ProductionDate);
}
公共车辆()
{}
}
公营车辆
{
公共汽车()
{
}
公共汽车(Int16车辆ID、日期时间、生产日期、Int16车辆属性1、Int16车辆属性2):基础(_车辆ID、生产日期)
{
this.AccidentID=u AccidentID;
this.ProductionDate=\u ProductionDate;
this.CarAttribute1=\u CarAttribute1
this.CarAttribute2=\u CarAttribute2
}
[主键,自动递增,列(“属性1”)]
公共Int16属性1{get;set;}
[列(“属性2”)]
公共Int16 CarAttribute2{get;set;}
}
我对C比较陌生,所以需要一些指导:)我错过了什么?在基类中,您应该使用属性而不是字段,所以请像这样调整基类:
public abstract class Vehicle : IComparable<Vehicle>, IComparable {
public Int16 AccidentID { get; set; }
public DateTime ProductionDate { get; set;}
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()
{}
致:
顺便说一句:基类中有VehicleID字段,但在构造函数中您将值设置为AccidentID而不是VehicleID。我认为这只是描述上的一个错误,对吗?所以我使用了AccidentID作为属性名,所以请检查它是否正确。1。您使用哪个框架来处理DB?2.您的代码有哪些问题?DB中的异常、错误或空数据?嗨,我使用的是mono和Xamarin IDE,其中我使用了一个名为SQLite.net async()的组件。我的数据库列中的基类属性为空。
public Int16 VehicleID;
public DateTime ProductionDate;
public Int16 AccidentID { get; set; }
public DateTime ProductionDate { get; set;}