首页 > 解决方案 > 如何使用 slite-net 在 C# 中忽略列表?

问题描述

我正在尝试实现观察者设计模式,对于一个表,我需要一个观察者列表。但是,我不希望将其添加到表格中。我尝试使用 [Ignore] 但我收到此错误:

attribute 'ignore' is not valid on this declaration type. it is only valid on 'property, indexer' declarations. (cs0592) (core)

这是我的课(表是活动):

[PrimaryKey, AutoIncrement]
        public int IDA { get; set; }
        public String name { get; set; }
        [Ignore] // this generates an error
        public List<IObserver> observers;

标签: c#sqlite-net

解决方案


答案在错误信息中,这部分:it is only valid on 'property, indexer' declarations

使观察者成为一个属性,而不是一个字段(即添加{ get; set; }到声明的末尾


推荐阅读