我今天开始使用RavenDB。当我保存一个类时,我可以在DB中看到Collection属性:
但是,当我加载该类时,该集合中没有任何项目:
public IEnumerable<CustomVariableGroup> GetAll()
{
using (IDocumentSession session = Database.OpenSession())
{
IEnumerable<CustomVariableGroup> groups = session.Query<CustomVariableGroup>();
return groups;
}
}
是否需要设置某种类型的激活深度才能查看属于POCO的属性?
编辑(按要求显示课程):
public class EntityBase : NotifyPropertyChangedBase
{
public string Id { get; set; } // Required field for all objects with RavenDB.
}
public class CustomVariableGroup : EntityBase
{
private ObservableCollection<CustomVariable> _customVariables;
public ObservableCollection<CustomVariable> CustomVariables
{
get
{
if (this._customVariables == null)
{
this._customVariables = new ObservableCollection<CustomVariable>();
}
return this._customVariables;
}
}
}
public class CustomVariable : EntityBase
{
private string _key;
private string _value;
/// <summary>
/// Gets or sets the key.
/// </summary>
/// <value>
/// The key.
/// </value>
public string Key
{
get { return this._key; }
set
{
this._key = value;
NotifyPropertyChanged(() => this.Key);
}
}
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>
/// The value.
/// </value>
public string Value
{
get { return this._value; }
set
{
this._value = value;
NotifyPropertyChanged(() => this.Value);
}
}
}
答案 0 :(得分:3)
知道了。 CustomVariables属性上没有setter。一旦我添加了私人二传手,它就有效了。所以,显然RavenDB不像db4o那样使用私有支持字段。 RavenDB需要该属性。
public ObservableCollection<CustomVariable> CustomVariables
{
get
{
if (this._customVariables == null)
{
this._customVariables = new ObservableCollection<CustomVariable>();
}
return this._customVariables;
}
private set
{
this._customVariables = value;
}
}
答案 1 :(得分:1)
您确定查询已执行吗?试试.ToArray()
或.ToList()
:
public IEnumerable<CustomVariableGroup> GetAll()
{
using (IDocumentSession session = Database.OpenSession())
{
IEnumerable<CustomVariableGroup> groups = session.Query<CustomVariableGroup>();
return groups.ToList();
}
}