我有这些类,活动记录模式的实现:
public abstract class RecordCollection<T> : ObservableCollection<T> where T : Record
public abstract class Record : INotifyPropertyChanged
每次我想定义数据库的一行(即联系人)时,我都会创建一个新的记录类,例如:
public class Contact : Record
和数据库行(即联系人)的集合为:
public class ContactCollection : RecordCollection<Contact>
但在那之后我不能使用泛型来包含记录集合:
ContactCollection contColl = new ContactCollection(databaseman dbMan);
contColl.Load();
RecordCollection<Record> recordColl = contColl;
它给了我“无法将 ContactCollection 类型隐式转换为 >”。任何帮助,将不胜感激。